gpt4 book ai didi

asp.net - 无法从 ASP.NET Web 应用程序连接到我的 SQL Server Express

转载 作者:行者123 更新时间:2023-12-03 04:46:34 24 4
gpt4 key购买 nike

我正在开发一个使用 SQL Server 作为数据库的工具。

首先我使用 Visual Studio 的 localdb,然后使用 Azure SQL Server,两者都工作得很好。

我现在尝试托管自己的 SQL Server Express,但似乎无法连接到它。它托管在 Azure VM 中,我已重新启动它,启用了 TCP,并在 Azure 中打开了端口 1433。

我尝试过远程连接、在本地计算机上运行 Web 应用程序并连接到 tcp:{IP}\InstanceName,以及在我的虚拟机上的 IIS 服务器上运行该应用程序在连接字符串中使用 .\InstanceName (尽管我仍然被告知检查服务器是否设置正确以处理 TCP?)

使用 Microsoft SQL Server Management Studio 在虚拟机上进行本地连接可以正常工作,因此我怀疑 web.config 中的连接字符串一定是错误的...

看起来像这样:

<connectionStrings>
<add name="defaultConnection"
connectionString="Server=tcp:12.345.678.910\InstanceName,1433;Initial Catalog=master;Persist Security Info=False;User ID=sa;Password={mypassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
providerName="System.Data.SqlClient" />
</connectionStrings>

我收到的错误消息是:

Server Error in '/application-name' Application. The remote computer refused the network connection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The remote computer refused the network connection

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: [Win32Exception (0x80004005): The remote computer refused the network connection]

[SqlException (0x80131904): 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: TCP Provider, error: 0 - The remote computer refused the network connection.)]

(还有更多,但似乎并不重要 - 如有必要或有帮助,将发布)

知道我做错了什么吗?

最佳答案

我自己找到了解决方案:

在服务器配置管理器中启用 TCP 是不够的,您还必须在 SQL Server 网络配置 > X 协议(protocol) > TCP > 属性 > IP 地址中将 IPAll 下的 TCP 端口设置为 1433。

关于asp.net - 无法从 ASP.NET Web 应用程序连接到我的 SQL Server Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46214068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com