System.Data.SqlClient.SqlException: The connection is broken and recovery is not possible
Hello,
I'm pretty new to EF and .NET Core, but I just thought I'd report an issue I had today and have been able to diagnose somewhat. It has to do with the runtime and applying a migration. In my ASP.NET Core project, when I removed the dnx451 framework from project.json (intending instead to rely entirely on the dnxcore50 framework) and I perform the following actions:
dnvm use default -r coreclr
dnx ef database update
I consistently get the below exception. To resolve, I need to restore the dnx451 framework in the project.json and use the mono runtime. Then, it works.
My database is SQL Server running on Amazon RDS.
Exception message:
Applying migration '20160323185819_Update1'.
System.Data.SqlClient.SqlException: The connection is broken and recovery is not possible. The connection is marked by the server as unrecoverable. No attempt was made to restore the connection.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlConnection.ValidateAndReconnect(Action beforeDisconnect, Int32 timeout)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.Data.Entity.Storage.Internal.RelationalCommand.<>c.<ExecuteNonQuery>b__13_0(DbCommand cmd, IRelationalConnection con)
at Microsoft.Data.Entity.Storage.Internal.RelationalCommand.Execute[T](IRelationalConnection connection, Func`3 action, String executeMethod, Boolean openConnection, Boolean closeConnection)
at Microsoft.Data.Entity.Storage.RelationalCommandExtensions.ExecuteNonQuery(IEnumerable`1 commands, IRelationalConnection connection)
at Microsoft.Data.Entity.Migrations.Internal.Migrator.Execute(IEnumerable`1 relationalCommands)
at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.Data.Entity.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)
ClientConnectionId:7f7dac22-d9a0-49cc-950b-5a532b754754
The connection is broken and recovery is not possible. The connection is marked by the server as unrecoverable. No attempt was made to restore the connection.
@robbpriestley thanks for reporting this. Could you provide more data on how to repro? E.g. what operating system and exact version of our bits are you using?
If you are using Linux what you are seeing might be related to https://github.com/dotnet/corefx/issues/4273, but that issue is supposedly fixed in RC1.
Hello @divega
Sure thing. I am running OSX and here's my dnvm list
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
1.0.0-rc1-update1 coreclr x64 darwin
* 1.0.0-rc1-update1 mono linux/osx default
I skimmed the dotnet/corefx#4273 issue and it does seem to be similar. At least my gut feeling is that The connection is broken and recovery is not possible is specific enough to suggest a connection. If it was fixed for Linux, perhaps not for OSX. (Although, I'm entirely not sure what MARS is)
Here's my project.json dependencies section as well
"dependencies": {
"System.Net.Security": "4.0.0-beta-22416",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.Relational": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final"
},
@robbpriestley MARS is the ability to process multiple active query results on the same connection at the same time. It is enabled in the connection string with this: "MultipleActiveResultSets=True".
I will move this issue to CoreFx since it seems to be a problem with SqlClient for .NET Core (and so that the right people can investigate) but please mention me if anything is required from the EF side.
This issue was moved to dotnet/corefx#7400
@divega, I'm not sure exactly how related this is is .NET Core versus EF but thanks for your help. Hopefully the CoreFx folks can gain some insights.
No problem.
To clarify, CoreFx is home for SqlClient, which manages the connection to SQL Server. When you switch between dnx451 and dnxcore50 the main thing that is changing is the SqlClient implementation that you are using. Since this works for you in dnx451 (i.e. on OSX this almost always means you are using the SqlClient implementation built-in in Mono), I suspect it could be a bug or limitation in SqlClient for .NET Core which is used on dnxcore50.