Ask a Question

TypeError: Failed to fetch - Unexpected behavior, retrieved dataset is empty

maujbs
Visitor

TypeError: Failed to fetch - Unexpected behavior, retrieved dataset is empty

My problem is that error "TypeError: Failed to fetch" is shown in Swagger UI and when API of endpoints is used.

The only way to bypass the error is using  SqlConnection, SqlCommand and DataReader to read data from DB, but in my case I need to use OleDbConnection, OleDbCommand and OleDbAdapter to Fill a Dataset, due to some restrictions when using the first approach.

This ONLY happens when the API is published live, localhost works like a charm.

 

//Procedure repository: Manage methods to retrieve Dataset and Execute queries
var repository = new ProcedureRepository(new Connection_Adapter().ConnString);
//Retrieve dataset
var dataSet = repository.GetWithProcedure(DbProcedure.ReporteVentasPorCliente, Cod_Cliente, Fecha_Inicio, Fecha_Final);
//Get datarows collection
var dataRows = dataSet.Tables[0].Rows;
//Convert a list of datarows to a list of typed objects
return dataRows.ToTypedCollection<Factura_General>();

 

The error occurs when the "Fill" method is called.

//Retrieve data from DB using storedProcedure and parameters.
public DataSet GetWithProcedure(string storedProcedure, params object[] parameters)
{
  var dataSet = new DataSet();
  //Instance the connection
  using (var dbConnection = new OleDbConnection(_connectionString))
  {
    //Instance the OleDbAdapter
    using (OleDbDataAdapter dbAdapter = new OleDbDataAdapter(storedProcedure, dbConnection)) 
    {
      OleDbCommand sqlCommand = dbAdapter.SelectCommand;
      sqlCommand.CommandType = CommandType.StoredProcedure;
      foreach (var parameterValue in parameters)
      {
        if (parameterValue == null) throw new System.Exception("No se acepta NULL en el valor del parametro");
        sqlCommand.Parameters.Add(_defaultParameterName, parameterValue.GetType().GetOleDbType()).Value = parameterValue;
      }
      dbConnection.Open();
      dbAdapter.Fill(dataSet); //**Dataset is not filled when executing API on live
    }
  }//The connection is closed and disposed
  return dataSet;
}

 

I want to add that no 500, 503 or any other error or exception is thrown, so it can be sent in the response.

I suppose that the swagger.json file is generated when I run Swagger, since I use this code in method:

ConfigureServices(IServiceCollection services)

services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version = "v1"
                });
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

and also this in Configure(IApplicationBuilder app, IWebHostEnvironment env) method:

app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "API supERPro");
            });

, so I reviewed the url which links to a the /swagger/v1/swagger.json and this is some of the data I found:

{
  "openapi": "3.0.1",
  "info": {
    "version": "v1"
  },
  "paths": {
    ...
    "/api/ReportesVentas/ReporteVentasPorCliente_Draft": {
"get": {
"tags": [
"ReportesVentas"
],
"parameters": [
{
"name": "Cod_Cliente",
"in": "query",
"schema": {
"type": "string",
"nullable": true
}
},
{
"name": "Fecha_Inicio",
"in": "query",
"schema": {
"type": "string",
"format": "date-time"
}
},
{
"name": "Fecha_Final",
"in": "query",
"schema": {
"type": "string",
"format": "date-time"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Factura_General"
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Factura_General"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Factura_General"
}
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"500": {
"description": "Server Error"
}
}
}
},
...

Please let me know what I am missing, or if this is a known issue and how to solve it.

Thanks

cancel
Showing results for 
Search instead for 
Did you mean: