I have a time series loaded into SQL Server, which i need to query and then allow multiple tasks to sequentially read the results from my SProc.
From what i have found on google, it seems possible to execute SProc’s or LINQ queries/statements. Im currently not familar with LINQ (SProc would be preferred approach). Is there any advantage of one over the other?
How would i access the data in a sequential manner after executing the SProc? Im assuming it SProc would just alter my ObjectContext. If this is the case, would i need each task to keep count of which row it was at and then access each parameter of the ObjectContext with this counter to get the required value?
The SProc code is below:
CREATE PROCEDURE [dbo].[DataRetrieval]
@StartTime Time(0) ='00:00:00',
@EndTime Time(0) ='00:00:00',
@StartDate Date ='2012-01-01',
@EndDate Date ='2012-01-01',
@Location nchar(6) ='Scotland'
AS
/*
Author: Hans
Date: 09-01-2013
Purpose: Used to load a large section of data into memory.
*/
SET NOCOUNT ON;
BEGIN
SELECT *
FROM
dbo.Data
WHERE
LOCATION = @Location
AND ( Date = @StartDate AND Time >= @StartTime
OR Date > @StartDate )
AND ( Date = @EndDate AND Time < @EndTime
OR Date < @EndDate )
ORDER BY
DATE, TIME
END
EDIT for USR
…
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "dbo.Data_GetStoredProcedureList";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandTimeout = 10;
cmd.Connection = connection;
try
{
connection.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader != null && reader.HasRows)
{
cancelTask.ThrowIfCancellationRequested();
while (reader.Read())
{
Entity rowData = new Entity();
rowData.RoutineName = reader["Routine_Name"].ToString();
rowData.ParameterName = reader["Parameter_Name"].ToString();
rowData.DataType = reader["Data_Type"].ToString();
sProcListRetrieval.Results.Add(rowData);
}
}
}
}
You can easily buffer a few million objects in memory. Buffer the results of the T-SQL in a
Listand pass that list to your worker threads.