尝试创建数据库时出错: Build 与SQL Server的连接时发生与网络相关或特定于实例的错误

loading...


0

我正在尝试在ASP.NET中编写应用程序,已经创建了模型,上下文并希望使用EF Code-First方法创建数据库,但它不起作用 .

此外,文件夹 App_Data 为空 . 我已经安装了SQL Server 2017 Express .

我尝试了所有可能找到的解决方案,但仍然无效 .

连接字符串:

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

但是,我收到此错误:

PM> update-database 

> Specify the '-Verbose' flag to view the SQL
> statements being applied to the target database

System.Data.SqlClient.SqlException(0x80131904): Build 与SQL Server的连接时发生与网络相关或特定于实例的错误 . 服务器未找到或无法访问 . 验证实例名称是否正确,以及SQL Server是否配置为允许远程连接 . (提供程序:SQL网络接口,错误:50本地数据库运行时发生错误 . 在LocalDB实例启动期间发生错误:SQL Server进程无法启动 . 错误:在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity标识,SqlConnectionString connectionOptions, SqlCredential凭证,对象providerInfo,字符串NEWPASSWORD,SecureString的newSecurePassword,布尔redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,池类DBConnectionPool,字符串的accessToken,布尔applyTransientFaultHandling)在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo, System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池,DbConnection owningObject,DbConnectionOptions选项,DbConnectionPoolKe)中的DbConnectionPool池,DbConnection owningConnection,DbConnectionOptions(userOptions) System.Data上的System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)上的System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)中的y poolKey,DbConnectionOptions userOptions) .ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection owningObject,UInt32的waitForMultipleObjectsTimeout,布尔allowCreate,布尔onlyOneCheckConnection,DbConnectionOptions USEROPTIONS,DbConnectionInternal&连接)在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection owningObject,TaskCompletionSource1重试,DbConnectionOptions USEROPTIONS,DbConnectionInternal&连接)在系统.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInter在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry,DbConnectionOptions userOptions)处于System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry,DbConnectionOptions userOptions)处的nal&connection)系统.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry)位于System.Data.SqlClction.SqlConnection.Open()的System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry),位于System.Data.Entity.Infrastructure.Interception . 在System.Data的System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch [TTarget,TInterceptionContext](TTarget目标,Action2操作,TInterceptionContext interceptionContext,Action3执行,Action3执行)中的DbConnectionDispatcher.b__36(DbConnection t,DbConnectionInterceptionContext c) . Entity.Inf System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy . <> c__DisplayClass1.b__0()的System.Data.Entity.SqlServer.SqlProviderServices . <> c__DisplayClass33.b__32()中的rastructure.Interception.DbConnectionDispatcher.Open(DbConnection连接,DbInterceptionContext interceptionContext) . System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func1操作)at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection) ,Action1 act)在System.Data的System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection,Action1 act)处于System.Data的System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable1 commandTimeout,DbConnection sqlConnection,String createDatabaseScript) . Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection连接,Nullable1 commandTimeout,StoreItemCollection storeItem集合)在System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection连接,Nullable1 commandTimeout,StoreItemCollection storeItemCollection)at at位于System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)的System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection连接)中的System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()位于System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update的System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)中的System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)(String targetMigration )System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run上的System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()ClientConnectionId:00000000-0000-0000-0000-000000000000

错误号:-1983577846,状态:0,类:20 Build 与SQL Server的连接时发生与网络相关或特定于实例的错误 . 服务器未找到或无法访问 . 验证实例名称是否正确,以及SQL Server是否配置为允许远程连接 . (提供程序:SQL网络接口,错误:50 - 发生本地数据库运行时错误 . 在LocalDB实例启动期间发生错误:SQL Server进程无法启动)

1回答

  • 0

    确保您的sql server已启动并正在运行 . 从Windows服务(services.msc)看 . 或者要确保尝试首先使用VS DB连接或SSMS手动连接 .

    尝试从您的SQL服务属性中检查此(下面) .
    enter image description here

loading...

评论

暂时没有评论!