我们创建的Web API查询OracleDB并返回大量记录,我们必须将其转换为JSON
以下是实际的控制器代码
public HttpResponseMessage Getdetails([FromUri] string[] id)
{
string connStr = ConfigurationManager.ConnectionStrings["ProDataConnection"].ConnectionString;
using (OracleConnection dbconn = new OracleConnection(connStr))
{
var inconditions = id.Distinct().ToArray();
var srtcon = string.Join(",", inconditions);
DataSet userDataset = new DataSet();
var strQuery = @"SELECT * from STCD_PRIO_CATEGORY where STPR_STUDY.STD_REF IN(" + srtcon + ")";
using (OracleCommand selectCommand = new OracleCommand(strQuery, dbconn))
{
using (OracleDataAdapter adapter = new OracleDataAdapter(selectCommand))
{
DataTable selectResults = new DataTable();
adapter.Fill(selectResults);
var returnObject = new { data = selectResults };
var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
ContentDispositionHeaderValue contentDisposition = null;
if (ContentDispositionHeaderValue.TryParse("inline; filename=ProvantisStudyData.json", out contentDisposition))
{
response.Content.Headers.ContentDisposition = contentDisposition;
}
return response;
问题是如果我们有大量的行如300,000它会抛出内存异常。我在其他论坛上读到这个问题可以通过分页来解决。但我希望立即获得整套记录,因为客户端应用程序在调用Web API时需要整个结果。我不知道如何处理这个问题。非常感谢任何帮助。
答案 0 :(得分:1)
我遇到了类似的问题,并通过在我的 web.config 中添加一些参数来解决这个问题:
<requestLimits maxAllowedContentLength="2147483647" />
(位于<system.webServer><security><requestFiltering>
)
和
<httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
(必须在<system.web>
)