Option 1:
Can you use SELECT TOP xxx in your stored procedure?
Oracle SELECT TOP 10 records
This will return the first xxxx number of records for the query allowing you to specify a limit.
you may want to think about having a different stored procedure for the service to call with the limited result set so the other queries return all data, or make the stored procedure have the number of records to return as an optional parameter.
Option 2:
Another option would be to using paging to read and process a number of records at a time.
Im not sure of the syntax for oracle, but it would look something like this in SQL:
This would probably be a better option as you are still processing all records from the query, just not all of them at once.
/// <summary>
/// Gets a list of Customers by name (with paging)
/// </summary>
/// <param name="oSageDatabase">The Sage database to query</param>
/// <param name="startIndex">The start index</param>
/// <param name="endIndex">The end index</param>
/// <param name="filter">The filter</param>
/// <returns>List of suppliers</returns>
public static List<SLCustomerAccount> GetCustomersByAccountNumber(SageDatabase oSageDatabase, int startIndex, int endIndex, string filter)
{
try
{
string query = @"
SELECT *
FROM
(
SELECT [SLCustomerAccount].*,
ROW_NUMBER() OVER (ORDER BY [SLCustomerAccount].[CustomerAccountNumber]) AS RowNumber
FROM [SLCustomerAccount]
LEFT JOIN [SLCustomerLocation]
ON [SLCustomerAccount].[SLCustomerAccountID]
= [SLCustomerLocation].[SLCustomerAccountID]
AND [SLCustomerLocation].[SYSTraderLocationTypeID]=0
WHERE [AccountIsOnHold]=0
AND [CustomerAccountNumber] + ' ' + [CustomerAccountName] + ' ' + [CustomerAccountShortName] + ' ' + ISNULL([SLCustomerLocation].[PostCode], '') LIKE @Filter
) as p
WHERE p.RowNumber BETWEEN @StartIndex AND @EndIndex
";
using (SqlCommand oSqlCommand = new SqlCommand(query))
{
oSqlCommand.Parameters.AddWithValue("@StartIndex", startIndex + 1);
oSqlCommand.Parameters.AddWithValue("@EndIndex", endIndex + 1);
oSqlCommand.Parameters.AddWithValue("@Filter", String.Format("%{0}%", filter));
using (DataTable dtSupplier = DataTier.ExecuteQuery(oSageDatabase.ConnectString, oSqlCommand))
{
return (from DataRow dr
in dtSupplier.Rows
select new SLCustomerAccount(dr, oSageDatabase)).ToList();
}
}
}
catch (Exception)
{
throw;
}
}
this will allow you to loop through say 100 records at a time from SQL which will help on memory etc, it depends on what you are doing with the data.
so first run you would pass in to the query 0 for start index, 100 for end index for example, then process the records, and increase your variables to get the next page of results. eg 101 start, 201 end