【问题标题】:ASP.NET Core not connecting to database on Windows Server 2012ASP.NET Core 未连接到 Windows Server 2012 上的数据库
【发布时间】:2017-08-04 22:06:47
【问题描述】:

我将我的 ASP.NET Core 应用程序发布到 Windows Server 2012 环境。我创建了一个新网站,将其指向该文件夹,并且运行良好。现在我正在尝试使应用程序连接到数据库。我安装了 SQL Server Express 2016 并编辑了我的项目,以便从数据库中检索数据。将我的“KSP_Backend.mdf”文件放到我的服务器上,并将该文件附加到 SQL Server Management Studio 中。数据库是完全可见的,所以它存在。

现在,当我尝试在已发布的项目文件夹“dotnet KSP_Backend.dll”中运行我的项目时,出现以下错误:

     Unhandled Exception: System.Data.SqlClient.SqlException: 
        A network-related or instance-specific error occurred while establishing 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. Thespecified LocalDB instance does not exist.)

这是我使用的“appsettings.json”文件中的连接字符串:

"Server=<My server's name>\\KSPSERVER;Database=KSP_Backend;Trusted_Connection=True;MultipleActiveResultSets=true"

我只是不确定连接字符串是否导致了我的错误。我的防火墙已关闭,LocalDB 已启动并运行。

【问题讨论】:

  • 当您通过 Management Studio 连接到 SQL Server 时,您的 SQL Server 名称是什么? &lt;My server's name&gt;\KSPSERVER 或者只是 &lt;My server's name&gt; 或者 &lt;My server's name&gt;\SQLExpress?连接字符串中的服务器名称应匹配。

标签: c# database asp.net-core windows-server-2012-r2 sql-server-2016-express


【解决方案1】:

当我没有在数据库服务器上启用“远程连接”时,我遇到了同样的问题。 在 SQL Management Studio 中,右键单击服务器名称,然后单击Properties,转到选项卡Connections,确保启用了Allow remote connections

另一件事可能是未启用 SQL Server TCP/IP 协议。 在SQL Server Configuration Manager 中,单击左侧窗格中的SQL Server Network Configuration,然后右键单击TCP/IP 并选择Enable

最后,您可能需要将 SQL Server Express 配置为侦听静态端口。您可以在此处找到有关此内容和前面几点的良好参考:SQL Express Remote Connections

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    相关资源
    最近更新 更多