Getting Timeout on stored procedure call - c#

I have a stored procedure which works fine when executed manually but when it is called on the code it return a Null Reference Exception because of a TimeOut. Here's the code:
private DataTable GetProcedure(DateTime dtStart, DateTime dtEnd) {
DataTable dt = new DataTable();
SqlDataReader reader;
string cs = //Connection String, it works everywhere, no need to put the code.
SqlConnection sqlConnection = new SqlConnection(cs);
string cmdText = "ProcedureName";
SqlCommand cmd = new SqlCommand(cmdText, sqlConnection);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter pFechaInicio = new SqlParameter("#dtStart", dtStart);
SqlParameter pFechaFin = new SqlParameter("#dtEnd", dtEnd);
cmd.Parameters.Add(pFechaInicio);
cmd.Parameters.Add(pFechaFin);
sqlConnection.Open();
reader = cmd.ExecuteReader(); //NULL REFERENCE EXCEPTION HERE
dt.Load(reader);
sqlConnection.Close();
return dt;
}
I made a manual call to the stored procedure with the exact same parameters and it worked fine (The stored procedure returns a 3 row / 2 column result with no NULLs whatsoever.
Even more, this error started happening 1 month ago but the program has been running for 6 months flawlesly.
EDIT: Here's some info on the SP:
SP header:
ALTER PROCEDURE [dbo].[SPName]
#dtStart datetime, #dtEnd datetime
AS
BEGIN
SET NOCOUNT ON;
select column1 as Name1, column2 as Name2
/* doesn't matter */
END
The specific result I'm getting when I execute the SP manually is:
column1 column2
1.0000000 105.426890
2.0000000 96.316330
3.0000000 82.849690
And here's the whole error code:
en System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
en System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
en System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
en System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
en System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
en System.Data.SqlClient.SqlDataReader.get_MetaData()
en System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
en System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
en System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
en System.Data.SqlClient.SqlCommand.ExecuteReader()
en BACK.OFERTAS.COBERTURAS.PRECIOS._01._00.StartJob.GetProcedure(DateTime dtStart, DateTime dtEnd) en C:\Users\Dell\Documents\BACK.OFERTAS.COBERTURAS.PRECIOS.01.00\StartJob.cs:línea 278
en BACK.OFERTAS.COBERTURAS.PRECIOS._01._00.StartJob.Start() en C:\Users\Dell\Documents\BACK.OFERTAS.COBERTURAS.PRECIOS.01.00\StartJob.cs:línea 176
Re-Reading the whole stackTrace it seems like a Timeout? How is that even possible, there SP is executed in less than 1 sec.

I've solved it changing the TimeOut time of the procedure (which was of 30 secs by default).
This happens because it isn't the same to execute a SP directly on the server than in the job.

Related

C# call to MS-SQL stored procedure not receiving parameters [duplicate]

This question already has an answer here:
Error With SqlCommand not accepting Parameter Arguments
(1 answer)
Closed 6 months ago.
The following image is the code used to call MS=SQL stored procedure, as you can see, I am attempting to provide parameters in the request
using (SqlConnection connection = new SqlConnection(sqlAuth)) {
// Open database connectionS
connection.Open();
// Call upon stored procedure
SqlCommand cmd = new SqlCommand("InsertSystem", connection);
cmd.Parameters.Add("#ObjectID", SqlDbType.VarChar).Value = Request.Form["objectid"].ToString();
cmd.Parameters.Add("#SystemID", SqlDbType.VarChar).Value = Request.Form["systemid"].ToString();
cmd.Parameters.Add("#ItemID", SqlDbType.Int).Value = Request.Form["itemid"].ToString();
int records = cmd.ExecuteNonQuery();
// Close database connection
connection.Close();
}
message = "Record Saved<br /><br />";
The error which is returned from this is as follows:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Procedure or function 'InsertSystem' expects parameter '#SystemID', which was not supplied.
Source=Core .Net SqlClient Data Provider
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ServiceObjectsWebApp.Pages.ObjectInsertModel.OnPost() in C:\Users\rmcd\Desktop\ServiceObecjts\ServiceObjectsWebApp\Pages\ObjectInsert.cshtml.cs:line 46
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.VoidHandlerMethod.Execute(Object receiver, Object[] arguments)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.<InvokeHandlerMethodAsync>d__29.MoveNext()
This exception was originally thrown at this call stack:
[External Code]
ServiceObjectsWebApp.Pages.ObjectInsertModel.OnPost() in ObjectInsert.cshtml.cs
[External Code]
You're calling a stored procedure so you need to tell it that:
cmd.CommandType = CommandType.StoredProcedure;

SQLDataReader. ExecuteReader times out

MS sql 2014 backend (on same machine) - Executereader times out (native error code: 258) # second executereader() in same connection. Why is this so?
(No big data amount involved, cmd strings involved are correct)
Note: it doesn't matter if all SELECT goes into separate connection the second always times out. It also doesn't matter if I'd use DataAdapter to catch data.... times out... see below, thanks for the ideas:
using (SqlConnection c = new SqlConnection(cString))
{
c.Open();
using (SqlCommand cmd = new SqlCommand(querystringPO, c))
{
cmd.Parameters.AddWithValue("#paramRecipe", productionOrderNo);
using (SqlDataReader rd = cmd.ExecuteReader())
{
dtRecipe = new DataTable();
dtRecipe.Load(rd);
rd.Close();
}
}
if (dtRecipe.Rows.Count > 0)
{
string querystringOpDefs = "SELECT * FROM ReferencedFieldsView_OperationDefinition WHERE RecipeID=#paramOpDef";
using (SqlCommand cmd1 = new SqlCommand(querystringOpDefs, c))
{
cmd1.Parameters.AddWithValue("#paramOpDef", dtRecipe.Rows[0].Field<int>("ID"));
using (SqlDataReader rd = cmd1.ExecuteReader())
{
dtOpDefs = new DataTable();
dtOpDefs.Load(rd);
rd.Close();
}
}
string querystringBOMItems = "SELECT * FROM ReferencedFieldsView_BomItem WHERE RecipeID=#paramBOMItem";
using (SqlCommand cmd2 = new SqlCommand(querystringBOMItems, c))
{
cmd2.Parameters.AddWithValue("#paramBOMItem", dtRecipe.Rows[0].Field<int>("ID"));
using (SqlDataReader rd = cmd2.ExecuteReader())
{
dtBOMItems = new DataTable();
dtBOMItems.Load(rd);
}
}
}
}
Ex below:
Exception: System.InvalidOperationException: Server operation encountered an exception ---> System.Data.SqlClient.SqlException: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: The wait operation timed out
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
Fact of the matter is that using SQL 2K12 the above snippet all worked (same database same etc)
However as sb suggested instead of selecting all fields (*), when explicitly added the req'd fields it started to work.

Webmatrix QueryValue call raising SQLException "Incorrect syntax near '0'."

The following method looks up an Id for an IMEI code
public static int GetId(string imei)
{
int returnVal = 0;
string sqlGetVehicle = "sp_Scalar_VehicleId_For_IMEI #IMEI = {0}";
using (var db = Database.Open("ClientApp"))
{
returnVal = db.QueryValue(sqlGetVehicle, imei);
}
return returnVal;
}
The sp it calls is set to return a single value. When run in SMO the procedure works fine. Give it an IMEI string, and if it's in the table it will return the vehicleId. If it isn't, it returns a 0.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: *trim*
-- Create date: 2017-05-12
-- Description: Returns the VehicleId Associated with an IMEI
-- =============================================
ALTER PROCEDURE [dbo].[sp_Scalar_VehicleId_For_IMEI]
#IMEI varchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE #VehicleId int
SELECT #VehicleId = v.VehicleId
FROM Vehicles v
WHERE v.TabletIMEI = #IMEI
-- ISNULL() in query wasn't working
IF #VehicleId IS NULL
BEGIN
SET #VehicleId = 0
END
SELECT #VehicleId
END
When run from code, the procedure throws System.Data.SqlClient.SqlException: Incorrect syntax near '0'. It was throwing this before I removed the ISNULL() check, and after I replaced it with the IF statement. What is the root cause of this error?
[SqlException (0x80131904): Incorrect syntax near '0'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +2442126
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5736904
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +628
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteScalar() +271
WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +111
*trim*.Forms.*trim*.Vehicle.GetId(String imei) in C:\Users\*trim*\Documents\Visual Studio 2017\WebSites\*trim*\App_Code\Vehicle.cs:258
ASP.Functions.UpdateSessionVehicle() in C:\Users\*trim*\Documents\Visual Studio 2017\WebSites\*trim*\App_Code\Functions.cshtml:148
ASP._Page_Default_cshtml.Execute() in C:\Users\*trim*\Documents\Visual Studio 2017\WebSites\*trim*\Default.cshtml:8
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
System.Web.WebPages.WebPage.ExecutePageHierarchy() +131
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +116
The placeholder for Webmatrix seems to be #0 instead of {0}. Also, to actually execute a stored procedure, it should be called with "Exec".
With that in mind, the command text should be defined as:
string sqlGetVehicle = "Exec sp_Scalar_VehicleId_For_IMEI #IMEI = #0";
According to this post another way could be:
returnVal = db.Query("Exec sp_Scalar_VehicleId_For_IMEI", imei);

Dapper .NET: problems with struct parameterized queries

I am trying to use structs as parameters in Dapper queries. It does not work for me. But it seems like it should work.
A failing example:
struct Simple { public int ID; }
[TestMethod]
public void StructParameter()
{
int result = Db.Query<int>("select [ID] = #ID", new Simple { ID = 123 }).First();
result.Should().Be(123);
}
A working example:
[TestMethod]
public void AnonymousParameter()
{
int result = Db.Query<int>("select [ID] = #ID", new { ID = 123 }).First();
result.Should().Be(123);
}
The error thrown in the first case:
System.Data.SqlClient.SqlException: Must declare the scalar variable "#ID".
Result StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.<QueryImpl>d__11`1.MoveNext() in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1553
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1443
...
I am using Dapper version 1.38.
Per suggestion by Dirk, property instead of a filed works just fine:
struct Simple {
public int ID { get; set; }
}
The problem is not caused by using structs, it's caused by using fields instead of properties.
If you'd change struct Simple into class Simple is still wouldn't work because the parameter reader creates only IL code to read properties.
Changing the ID field into a property will solve it.

SqlConnection Time out error through ASP.NET WEB API

I am trying to execute a stored procedure (query) from the ASP Web API. I have developed it (command timeout is 300 seconds).
At the beginning, calling the stored procedure from Web API is very fast, but after a few days when calling the same WEB API, it gives me time out error (shown below).
Meanwhile if I try to execute the same stored procedure with the same parameter even at the same time directly from SQL Server Management Studio, it is executed within seconds.
The code :
public List<ScheduledTitles> GetScheduledTitles(CriteriaFields _criteria)
{
try
{
System.Data.DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
using (SqlConnection con = new SqlConnection(_strDBConnection))
{
con.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = con;
comm.CommandText = "spQuery_1";
comm.Parameters.Add(new SqlParameter() { ParameterName = "Product_Line_ID", SqlDbType = SqlDbType.Int, Value = _criteria.ProductLineID == null ? (object)System.DBNull.Value : _criteria.ProductLineID });
comm.CommandType = CommandType.StoredProcedure;
da.SelectCommand = comm;
comm.CommandTimeout = 300;
da.Fill(ds);
}
.
.
.
return scheduledTitlesS.ToList<ScheduledTitles>();
}
catch (Exception exc)
{
throw exc;
}
}
The error message:
The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at HERS_SearchQuery.Data.DataAccess.SQLServer.HERSScheduleRepository.GetScheduledTitles(CriteriaFields _criteria) in C:\Users\nah\Documents\Visual Studio 2010\Projects\HERS_SchedulerSearch\HERS_SearchQuery.Data\DataAccess\SQLServer
I had a similar issue a couple of years ago, I solved it by using the option
WITH RECOMPILE
in the strored procedure. It happened that SQL SERVER was caching an execution plan that was not efficient for all parameters.
Of course I don't know whether this can solve your problem, but I think it's worth to try.

Categories

Resources