Entity Framework 6: Connection Error

Asked

Viewed 470 times

0

I created a project with Entity Framework 6 and another Console Application type project, containing the following connection string in the App.Config file:

<connectionStrings>
    <add name="ConnString" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0; Initial Catalog=MeuDB; Integrated Security=True" />  
</connectionStrings>

I added "Connstring" in the Dbcontext constructor and then enabled Migrations and ran the "Update-Database -Verbose" command".

Before the error happens below, I followed all the steps to configure SQL Server for remote access.

Using Startup project 'Meuprojeto.Console'.
Using Nuget project 'Meuprojeto.Infra.Data'.
Specify the '-Verbose' flag to view the SQL statements being Applied to the target database.
Target database is: 'Meuprojetodb' (Datasource: (Localdb) v11.0, Provider: System.Data.Sqlclient, Origin: Configuration).
System.Data.Sqlclient.Sqlexception (0x80131904): Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for details of the error. )
in System.Data.Sqlclient.SqlInternalConnectionTds.. ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Dbconnectionpool pool, String accessToken, Boolean applyTransientFaultHandling) em System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) em System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) em System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) em System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) em System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) on System.Data.Providerbase.DbConnectionPool.Trygetconnection(Dbconnection owningObject, Taskcompletionsource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) em System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 Retry, Dbconnectionoptions userOptions, Dbconnectioninternal oldConnection, Dbconnectioninternal& Connection) em System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) em System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 Retry, Dbconnectionoptions userOptions) in System.Data.Sqlclient.SqlConnection.Tryopeninner(Taskcompletionsource1 retry) em System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 Retry) in System.Data.Sqlclient.SqlConnection.Open() in System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(Dbconnection t, Dbconnectioninterceptioncontext c) in System.Data.Entity.Infrastructure.Interception.Internaldispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action2 Operation, Tinterceptioncontext interceptionContext, Action3 executing, Action3 executed) in System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(Dbconnection Connection, Dbinterceptioncontext interceptionContext) in System.Data.Entity.SqlServer.Sqlproviderservices.<>c__DisplayClass33.b__32() in System.Data.Entity.SqlServer.Defaultsqlexecutionstrategy.<>c__DisplayClass1.b__0() in System.Data.Entity.SqlServer.Defaultsqlexecutionstrategy.Execute[Tresult](Func1 operation) em System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) em System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action1 Act) in System.Data.Entity.SqlServer.Sqlproviderservices.Usingmasterconnection(Dbconnection sqlConnection, Action1 act) em System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable1 commandTimeout, Dbconnection sqlConnection, String createDatabaseScript) in System.Data.Entity.SqlServer.Sqlproviderservices.Dbcreatedatabase(Dbconnection Connection, Nullable1 commandTimeout, StoreItemCollection storeItemCollection) em System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable1 commandTimeout, Storeitemcollection storeItemCollection) in System.Data.Entity.Core.Objects.ObjectContext.Createdatabase() in System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(Dbconnection Connection) in System.Data.Entity.Migrations.Dbmigrator.Ensuredatabaseexists(Action mustSucceedToKeepDatabase) in System.Data.Entity.Migrations.Infrastructure.MigratorBase.Ensuredatabaseexists(Action mustSucceedToKeepDatabase) in System.Data.Entity.Migrations.Dbmigrator.Update(String targetMigration) in System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) in System.Data.Entity.Migrations.Design.ToolingFacade.Updaterunner.Runcore() in System.Data.Entity.Migrations.Design.ToolingFacade.Baserunner.Run() ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:-1983577832,State:0,Class:20 Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows App event log for details of the error. ) PM> Update-Database -Verbose Using Startup project 'Meuprojeto.Console'. Using Nuget project 'Meuprojeto.Infra.Data'. Specify the '-Verbose' flag to view the SQL statements being Applied to the target database. Target database is: 'Meuprojetodb' (Datasource: (Localdb) v11.0, Provider: System.Data.Sqlclient, Origin: Configuration). System.Data.Sqlclient.Sqlexception (0x80131904): Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows App event log for details of the error. ) in System.Data.Sqlclient.SqlInternalConnectionTds.. ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Dbconnectionpool pool, String accessToken, Boolean applyTransientFaultHandling) em System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) em System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) em System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) em System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in System.Data.Providerbase.DbConnectionPool.Trygetconnection(Dbconnection owningObject, Uint32 waitForMultipleObjectsTimeout,1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) em System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 Retry, Dbconnectionoptions userOptions, Dbconnectioninternal oldConnection, Dbconnectioninternal& Connection) em System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) em System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 Retry, Dbconnectionoptions userOptions) in System.Data.Sqlclient.SqlConnection.Tryopeninner(Taskcompletionsource1 retry) em System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 Retry) in System.Data.Sqlclient.SqlConnection.Open() in System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(Dbconnection t, Dbconnectioninterceptioncontext c) in System.Data.Entity.Infrastructure.Interception.Internaldispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action2 Operation, Tinterceptioncontext interceptionContext, Action3 executing, Action3 executed) in System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(Dbconnection Connection, Dbinterceptioncontext interceptionContext) in System.Data.Entity.SqlServer.Sqlproviderservices.<>c__DisplayClass33.b__32() in System.Data.Entity.SqlServer.Defaultsqlexecutionstrategy.<>c__DisplayClass1.b__0() in System.Data.Entity.SqlServer.Defaultsqlexecutionstrategy.Execute[Tresult](Func1 operation) em System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) em System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action1 Act) in System.Data.Entity.SqlServer.Sqlproviderservices.Usingmasterconnection(Dbconnection sqlConnection, Action1 act) em System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable1 commandTimeout, Dbconnection sqlConnection, String createDatabaseScript) in System.Data.Entity.SqlServer.Sqlproviderservices.Dbcreatedatabase(Dbconnection Connection, Nullable1 commandTimeout, StoreItemCollection storeItemCollection) em System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable1 commandTimeout, Storeitemcollection storeItemCollection) in System.Data.Entity.Core.Objects.ObjectContext.Createdatabase() in System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(Dbconnection Connection) in System.Data.Entity.Migrations.Dbmigrator.Ensuredatabaseexists(Action mustSucceedToKeepDatabase) in System.Data.Entity.Migrations.Infrastructure.MigratorBase.Ensuredatabaseexists(Action mustSucceedToKeepDatabase) in System.Data.Entity.Migrations.Dbmigrator.Update(String targetMigration) in System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) in System.Data.Entity.Migrations.Design.ToolingFacade.Updaterunner.Runcore() in System.Data.Entity.Migrations.Design.ToolingFacade.Baserunner.Run() ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:-1983577832,State:0,Class:20 Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for details of the error. )

  • 1

    The error says you were unable to connect to SQL Server. You have Localdb version 11 installed even?

  • I installed SQL Server Management Studio v17.2 on localhost. This Localdb does not refer to localhost?

  • 1

    No. It refers to the SQL Server Localdb service.

  • Ah, yes. I will look for other connection strings. thanks!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.