0

When I try to add a string field to a domain object, and then I run add-migration, I get the following error:

PM> add-migration add-field-to-contact System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) ---> System.ComponentModel.Win32Exception (0x80004005): An existing connection was forcibly closed by the remote host

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.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at System.Data.SqlClient.TdsParserStateObject.TryReadByteArray(Byte[] buff, Int32 offset, Int32 len, Int32& totalRead) at System.Data.SqlClient.TdsParserStateObject.TryReadString(Int32 length, String& value) at System.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj, SqlCommandColumnEncryptionSetting columnEncryptionOverride, String columnName) at System.Data.SqlClient.SqlDataReader.TryReadColumnData() at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly) at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn) at System.Data.SqlClient.SqlDataReader.GetString(Int32 i) at lambda_method(Closure , Shaper ) at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator1.ReadNextElement(Shaper shaper) at System.Data.Entity.Core.Common.Internal.Materialization.Shaper1.SimpleEnumerator.MoveNext() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations) at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations() at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges) at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) ClientConnectionId:5682a620-7a08-4c70-815f-591d8bf49ab6 Error Number:10054,State:0,Class:20 A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

I have tried the following:

  • I checked all connection strings.
  • I tried adding the migration from another machine (failed with same error).
  • I tried adding a migration to the same server but to a restored database (failed with same error).
  • I tried adding a migration on a different application to the same server, different database (Worked perfect).
  • I restored my live db which is a few migrations behind my dev environment. The first update-database I called worked. all calls after failed with the same error.

Any help will be appreciated.

jarlh
  • 42,561
  • 8
  • 45
  • 63
Skbenga
  • 105
  • 1
  • 7
  • https://stackoverflow.com/questions/2582036/an-existing-connection-was-forcibly-closed-by-the-remote-host In particular you might have a circular reference as mentioned by one of the answers. – gilliduck Apr 04 '19 at 13:14
  • @gilliduck thanks for your suggestion. my last successful migration was yesterday morning a few hours before all of the above started. if there was a circular reference i would have seen this behavior sooner. However, after seeing your response, i have gone through all my domain models to be sure. – Skbenga Apr 04 '19 at 13:52
  • The mapping between the Entity Classes and the Database are not matching. You need to update the Entity Model to match the current database. The mapping is not forward/backwards compatible. You need a different Entity Model for each version of the database. To prevent these errors it is recommended that you have a database version and check the version with the version of the c# code. – jdweng Apr 04 '19 at 14:29
  • I ended up pulling a copy of the live db to my local machine and reapplied the updates. now everything is working again. I then did the same with my dev server (again) and that also worked. I have no idea what caused the issue but it seems to be resolved. – Skbenga Apr 05 '19 at 12:51

0 Answers0