I using Entity Framework to execute Stored Procedures (Azure SQL Server) in my data-base.
My C# code looks like this:
using (var context = new MyDataContext())
numberOfEffectedRows = context.MySPName(this.Id);
In most cases (99.9%) of the executions, this works fine. But, sometimes it's failed with this error:
System.InvalidOperationException: Invalid operation. The connection is closed.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlInternalTransaction.Rollback()
at System.Data.SqlClient.SqlInternalTransaction.Dispose(Boolean disposing)
at System.Data.SqlClient.SqlTransaction.Dispose(Boolean disposing)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbTransactionDispatcher.Dispose(DbTransaction transaction, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityTransaction.Dispose(Boolean disposing)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass4b.<ExecuteFunction>b__49()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters)
at ***.MyDataContext.MySPName(Nullable`1 Id) in ***
at ***.DoSomething() in ***
When this happening:
Someone known why this happens and how I can know if my Stored Procedure is executed or not?
The connection is closed is due to timeout, so suggest you to check your Connect Timeout
in your connection string
connectionString="Data Source=..;Initial Catalog=;Persist Security Info=..;User ID=..;Password=..;Connect Timeout=.."
For diagnostic i suggest you to run SQL Server Profiler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With