I am sorry before because the title too general. I just wonder how it's happen in this code:
foreach (var item in list)
{
.........
using (SqlCommand cmd = new SqlCommand(#"SELECT some_fields FROM tbl WHERE id=#id", new SqlConnection(db.ConnectionString)))
{
cmd.Connection.Open();
cmd.Parameters.AddWithValue("#id", item.id);
var reader = cmd.ExecuteReader();
while (reader.Read())
{
//do something
}
cmd.Connection.Close();
}
.........
}
Execution timeout happened on the second loop. First loop was no problem. Is there something wrong in this syntax? Please tell me.
Exception thrown at ExecuteReader():
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, Boolean isInternal, Boolean forDescribeParameterEncryption)
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()
at HPM_WEB.Areas.InventoryManagementForms.Transaction.OutboundTransaction.InsertOrUpdateDetailOutbound(MOutboundAdviseModel mout, List`1 doutList, SqlConnection connection, SqlTransaction transaction, String message) in F:\MyFolder\..\Transaction.cs:line 444
Thanks in advance
Try increasing the Connection Timeout
// Setting command timeout to 3 Minutes (60*3=180 Seconds)
cmd.CommandTimeout = 60*3;
Do this before ExecuteReader()
How long it takes for your cmd.ExecuteReader(); to execute?
in your connectionstring, you may want to get a try by allowing multiple active resultset.
see if this resolve your issue? like:
<add name="yourDBConn" connectionString="Data Source=yourInstance;Initial Catalog=yourDB;Persist Security Info=True;User ID=user;Password=pwd;Connection Timeout=30;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
A value of 0 indicates no limit (an attempt to execute a command will wait indefinitely).
The default is 30 seconds. if Read requires two network packets, then it has 30 seconds to read both network packets. If you call Read again, it will have another 30 seconds to read any data that it requires.(Here is the problem exist before expiring timeout it is again calling reader )
Solution 1 is increasing the connection timeout or setting the value to Zero. Another Solution might work is use using(var reader = cmd.ExecuteReader();
Related
I am trying get the data from database but I am getting this error. I am sure I am missing some simple logic but I couldn't figure out what's wrong with the query as it is working fine directly on DB.
SqlCommand retrievedgeids = new SqlCommand("Select edgeid from Edges where fromIntersection = #fromid and toIntersection = #toid", sqlconnection);
retrievedgeids.Parameters.AddWithValue("#fromid", fromid);
retrievedgeids.Parameters.AddWithValue("#toid", toid);
using (SqlDataReader reader = retrievedgeids.ExecuteReader())
{
while (reader.Read())
{
if (reader["edgeid"] != System.DBNull.Value)
{
edgeids.Add(Convert.ToInt32(reader["edgeid"]));
}
}
}
And this is the error message:
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '='.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.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, 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()
at NewRNG.UpdatedRNG.getalledges() in C:\Users\ssindhu\source\repos\NewRNG\NewRNG\UpdatedRNG.cs:line 148
ClientConnectionId:36446293-901d-49a3-85a7-da73e2acaedd
Error Number:102,State:1,Class:15
Can you help me figure out this issue?
Here is the link to the Microsoft documentation for the Parameter class you are using :
https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlparameter?view=dotnet-plat-ext-5.0
You would need to change your code to something like this :
System.Data.SqlClient.SqlCommand retrievedgeids = new System.Data.SqlClient.SqlCommand("Select edgeid from Edges where fromIntersection = #fromid and toIntersection = #toid", sqlconnection);
System.Data.SqlClient.SqlParameter fromIdParameter = new System.Data.SqlClient.SqlParameter("fromid", SqlDbType.Int);
fromIdParameter.Value = fromId;
retrievedgeids.Parameters.Add(fromIdParameter);
Use Parameters.Add instead of AddWithValue like this:
retrievedgeids.Parameters.Add("#fromid", SqlDbType.Int);
retrievedgeids.Parameters["#fromid"].Value = fromid;
I'm opening SQL connection then running many SQL scripts in it. My program doesn't close connection at any spot but if I call Thread.Abort() then the connection sometimes gets closed (50/50).
The code looks like:
connection.Open();
try
{
// running various SQL script, no one is closing connection
// calling Thread.Abort() at this point
}
catch (ThreadAbortException ex)
{
Thread.ResetAbort();
// connection sometimes has state "Closed" here!!!
new SqlCommand("blahblah", connection).ExecuteNonQuery(); // doesn't work then
}
Why it's happening? What should I do to have it alive until I explicitly close it?
This is call stack when connection is closed:
at SNIReadSyncOverAsync(SNI_ConnWrapper* , SNI_Packet** , Int32 )
at SNINativeMethodWrapper.SNIReadSyncOverAsync(SafeHandle pConn, IntPtr& packet, Int32 timeout)
at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
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()
I have a C# script meant to calculate a MD5 checksum of an online article as such:
using System;
public class Script
{
public static string TransformContent(ContentTransformationArguments args)
{
// CONVERT CAPTURED FIELD INTO BYTE ARRAY
var buffer = System.Text.Encoding.UTF8.GetBytes(args.Content);
var md5Hash = string.Empty;
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) {
// COMPUTE MD5 HASH AND CONVERT TO STRING
md5Hash = BitConverter.ToString(md5.ComputeHash(buffer)).Replace("-", String.Empty);
}
return md5Hash;
}
}
The above generates a data element called "ChecksumElement" - then I have an export script which serves to write the datum to a field in our SQL Server called Checksum2, of data type varbinary(16):
using (var sqlConnection = new SqlConnection(sqlString.ConnectionString))
{
sqlConnection.Open();
using (IExportReader dataReader = args.Data.GetTable())
{
while (dataReader.Read()) // Loop through Export data rows
{
var checksumBytes = System.Text.Encoding.UTF8.GetBytes(dataReader.GetStringValue("ChecksumElement"));
using (var sqlCommand = new SqlCommand())
{
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandText = #"INSERT INTO [dbo].[Data1] (
Checksum2)
VALUES (,
#ChecksumElement)";
sqlCommand.Parameters.AddWithValue("#ChecksumElement", checksumBytes);
sqlCommand.ExecuteNonQuery();
}
}
}
}
The issue is that running the export script throws the following error:
"System.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated.
The statement has been terminated.
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.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)
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.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Script.ExportData(DataExportArguments args)
ClientConnectionId:492cda62-285f-4a74-903d-55c7b7acee30
Error Number:8152,State:11,Class:16"
It would appear that it's having trouble writing the checksum in its current format to the varbinary(16) field. Does anyone know how I can tweak this code to, perhaps convert the checksum to the proper format before it hits the database table? Please note, that per a suggestion of a colleague, I changed "UTF8" to "ASCII" in the two places in the above code, but I get the same error. Changing the data type of the database field is unfortunately not an option.
I'm trying to save 8,000 characters to a SQL Server Express database table, and this may be smaller or larger in the future, and I'm getting an exception saying that the data will be truncated.
I've already set the column to varchar(max) and don't know if there is another setting for the ORM itself.
Any help is appreciated
Update failed: Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.
The statement has been terminated. ---> System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
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.ExecuteReader(CommandBehavior behavior)
at OpenAccessRuntime.CommandWrapper.ExecuteReader(CommandBehavior behavior)
at Telerik.OpenAccess.Runtime.Logging.LoggingDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.CommandImp.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.RelationalStorageManager.generateUpdates(OID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, Boolean haveNewObjects, CharBuf s, BatchControlInfo batchControl, Boolean previousInserts)
Row: GenericOID#bd4840c1 TokenRequest TokenID=ae428dc3-5815-42ac-bbd6-e4a3f8e87132
UPDATE [TokenRequest] SET [PI]=?, [ReqState]=?, [second_message_date]=?, [second_message_j_s_o_n]=?, [TI]=? WHERE [TokenID] = ? AND [ReqState] is null AND [second_message_date]=?
(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.
The statement has been terminated. ---> System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
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.ExecuteReader(CommandBehavior behavior)
at OpenAccessRuntime.CommandWrapper.ExecuteReader(CommandBehavior behavior)
at Telerik.OpenAccess.Runtime.Logging.LoggingDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.CommandImp.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.RelationalStorageManager.generateUpdates(OID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, Boolean haveNewObjects, CharBuf s, BatchControlInfo batchControl, Boolean previousInserts)
#makerofthings7, my best guess about the re-appearance of the error after the fix is that the model and the database are not in synchronous.
It seems that you have modified the table in the storage model in Visual Designer and in order to complete the fix, I would suggest to you to run the Update Database From Model wizard and to transfer the change in the database.
I hope this helps.
I am working with a Console app that is using Parallel.foreach for threading purposes.
It was developed using .net 4.5 vs 2012 that is retrieving and inserting data into sql server (2008 r2) that is on site. So there should be no network issues because the sql server is local. My application is currently the only one using the database I am getting a ton of timeouts from several threads at the same time. What makes this more confusing is I can call this application over and over but that one time I get the timeout. Maybe this is simple as increasing the timeout but I wonder if there is something else going on
This is the stored procedure I am calling
Select table.Id from Table WITH (NOLOCK)
inner join table2 c WITH (NOLOCK) on c.Id = table.TableId
inner join Table3_xref x WITH (NOLOCK) on x.TableID = c.id
inner join Table4 p WITH (NOLOCK) on p.id = x.id
where
value = #Parm1
and p.Value1 = #Parm2
and c.Value2 = #Parm3
and Table.Void = 0
This is the exception
System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.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)
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()
This is what my code looks like
try
{
using (DbConnection con = Database.CreateConnection())
{
IDbCommand cmd = new SqlCommand(sSQL, (SqlConnection)con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
IDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
result = true;
}
}
}
After a while the program is able to recover and continue its task. I would consider this a duplicate to this but I am not using database mirroring and this is not happening on connection.open
I can increase the time out from the default but I am not real sure this should be a issue.