The specified LocalDB instance does not exist

I am trying to create an ASP.NET MVC 5 web application in SQL Server 2015 Express using EntityFramework 6, but when I debug the application and go to the page where the database is needed, I get the following error.

System.Data.SqlClient.SqlException was not processed by user code ErrorCode = -2146232060 HResult = -2146232060 LineNumber = 0 Message = Error relacionado con la red o específico de la instancia mientras se> establecía una conexión con el servidor SQL Server. Not if you do not have access. Compruebe que el nombre de la instancia es correcto> y que SQL Server esta configurado para admitir conexiones remotas. (provider:> SQL Network Interfaces, error: 50 - Se produjo un error de Local Database> Runtime. La instancia de LocalDB especificada no existe.)

This error mentions a remote connection problem, but this is not possible because I am local. Then I get the following error: LocalDB instance local error occurred. The specified LocalDB instance does not exist.

Stacktrace:

    en 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)
       en System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       en System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       en System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       en System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       en System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       en System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       en System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       en System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       en System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       en System.Data.SqlClient.SqlConnection.Open()
       en System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
       en System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       en System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
       en System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
       en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
       en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
       en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
       en System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
       en System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
       en System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
       en System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       en System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       en System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       en System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
       en System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       en System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       en System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
       en System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState)
       en System.Data.Entity.Database.Create(DatabaseExistenceState existenceState)
       en System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
       en System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
       en System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       en System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
       en System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
       en System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
       en System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
       en System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
       en System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       en System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       en System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
       en System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
       en System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       en System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       en WebApplication10.Controllers.AlbumsController.Index() en C:\Users\Develop2\Documents\Visual Studio 2015\Projects\WebApplication10\WebApplication10\Controllers\AlbumsController.cs:línea 20
       en lambda_method(Closure , ControllerBase , Object[] )
       en System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       en System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       en System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       en System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
       en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
       en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
       en System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       en System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
       en System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()


:

 <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication10-20151208105118.mdf;Initial Catalog=aspnet-WebApplication10-20151208105118;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="WebApplication10Context" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=WebApplication10Context-20151208105514; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|WebApplication10Context-20151208105514.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>

2

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="v11.0" />  
    </parameters>
     </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

?

, , localDB , sqllocaldb c MSSQLLocalDB 11.0

+4
2

, , aspnet-WebApplication10-20151208105118.mdf WebApplication10Context-20151208105514.mdf App_Data ( .

-, (LocalDb)\MSSQLLocalDB (LocalDb)\v11.0.

-, :

<add name="WebApplication10Context" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=WebApplication10Context-20151208105514; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|\WebApplication10Context-20151208105514.mdf" providerName="System.Data.SqlClient" />

-, , SQL Server , LocalDB.


, App_Data > > ...

New SQL

+1

LocalDB, Microsoft , . SQL Server LocalDB Visual Studio , SQL. http://www.nikgupta.net/2015/12/connect-localdb-from-management-studio/

0

Source: https://habr.com/ru/post/1619053/


All Articles