更新数据库-(localdb)\ MSSQLLocalDB错误 [英] Update-Database - Error with (localdb)\MSSQLLocalDB

查看:156
本文介绍了更新数据库-(localdb)\ MSSQLLocalDB错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行Add-Migration后运行Update-Database时出现以下问题:

I am getting the following issue when running Update-Database after running Add-Migration:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称正确,并且已将SQL Server配置为允许远程连接.(提供者:SQL网络接口,错误:50-发生本地数据库运行时错误.指定的LocalDB实例名称无效.)

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid. )

SQL本地数据库:

在Startup.cs中:

 // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        //services.AddDbContext<MyContext>(options => options.UseSqlServer(Configuration["ConnectionStrings = DefaultConnection"]));
        //var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.NewDb;Trusted_Connection=True;ConnectRetryCount=0";
        //var connection =    @"Data Source = (localdb)\\MSSQLLocalDB; Database = Ecommerce2DB; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";
        var connection = @"Data Source = (localdb)\\MSSQLLocalDB; Initial Catalog = Ecommerce2DB; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";
            //                      Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = master; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False
        services.AddDbContext<MyContext>(options => options.UseSqlServer(connection));

    }

推荐答案

此错误消息通知您无法连接到MSSQL Server和应用程序将不会连接到数据库.可能的原因和消除步骤如下:

This error message informs you that it is not possible to connect to MSSQL Server and app will not connect to the database. The possible reasons and the step for elimination are described below:

1)MSSQL Server未启动.从它的开始,您可以在可用的MSSQL Server的下拉列表中查看您的MSSQL Server/实例.

1) MSSQL Server is not started. Starting of it will allow you to see your MSSQL Server/instance in the drop-down list of available MSSQL Servers.

a)转到开始"菜单->控制面板"->管理工具"->服务".

a) Go to the Start menu -> Control Panel -> Administration Tools -> Services.

b)在服务列表中找到SQL Server(实例名称,默认情况下为.)并检查其状态,必须将其启动(如果尚未启动,请右键单击SQL Server并从启动"中选择启动").上下文菜单).

b) In the list of services find SQL Server (instance name, by default it is .) and check its status, it must be Started (if it is not started, then right click on SQL Server and select Start from the context menu).

2)防火墙阻止了端口1433(用于连接的MSSQL标准端口).可以按照以下步骤将其禁用:

2) Firewall is blocking port 1433 (MSSQL standard port for connections). It can be disabled following the steps below:

a)转到开始"菜单->控制面板"->管理工具"->服务".

a) Go to the Start menu -> Control Panel -> Administration Tools -> Services.

b)查找防火墙服务,必须将其禁用(如果未禁用,请右键单击该服务,然后从上下文菜单中选择停止".)

b) Find Firewall service, it must be disabled (if it is not, then right click the service and select Stop from the context menu).

注意:有关此问题的更多信息,请访问Microsoft官方网站:http://msdn.microsoft.com/zh-cn/library/cc646023.aspx

Note: More information on this can be found on the official Microsoft site: http://msdn.microsoft.com/en-us/library/cc646023.aspx

3)MSSQL协议禁用了TCP/IP协议.要启用它,请参见以下步骤:

3) TCP/IP protocol is disabled for MSSQL protocols. To enable it, see the steps below:

a)在开始"菜单中导航到"SQL Server配置管理器".

a) Navigate to SQL Server Configuration Manager in the Start menu.

b)在SQL Server配置管理器中指定TCP/IP协议的设置.

b) Specify settings for TCP/IP protocol in SQL Server Configuration Manager.

c)重新启动计算机.

c) Restart the computer.

注意:有关此问题的更多信息,请访问Microsoft的官方网站:

Note: More information on this can be found on the official Microsoft site: http://msdn.microsoft.com/en-us/library/bb909712%28v=vs.90%29.aspx

4)确保将数据库引擎配置为接受远程连接(如果使用的是集中式数据库):

4) Make sure your database engine is configured to accept remote connections (If you are using centralized database):

a)打开SQL Server Management Studio.b)右键单击SQL Server实例->属性->连接->选中允许远程连接到此服务器框.c)转到常规"部分,然后检查在名称"字段中指定的SQL Server的名称.

a) Open SQL Server Management Studio. b) Right click SQL Server instance -> Properties -> Connections -> Check the Allow remote connections to this server box. c) Go to the General section and check name of SQL Server specified in the Name field.

5)如果使用的是命名的SQL Server实例,请确保在连接字符串中使用该实例名称.通常,指定数据库服务器所需的格式为machinename \ instancename.

5) If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings. Usually the format needed to specify the database server is machinename\instancename.

6)确保您的登录帐户对您在登录期间使用的数据库具有访问权限.

6) Make sure your login account has access permission on the database you used during login.

替代:如果仍然无法建立任何连接,则可能需要在服务器上创建一个SQL帐户,在服务器上创建一个相应的SQL用户有问题的数据库,只需使用此用户名/密码登录数据连接到SQL Server.

Alternative: If you still can’t get any connection, you may want to create a SQL account on the server, a corresponding SQL user on the database in question, and just use this username/password login data to connect to SQL Server.

这篇关于更新数据库-(localdb)\ MSSQLLocalDB错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆