Asp.Net 4.5 应用程序和 SQL Server 2012 之间的连接问题
Connection issue between Asp.Net 4.5 app and SQL Server 2012
我有一个连接到 SQL Server 2012 数据库的 Web 表单应用程序。当我尝试在应用程序中打开连接时出现此错误:
System.Data.SqlClient.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 - No connection could be made because the target machine actively refused it.) ---> ...
我已经检查 SQL 服务器配置为允许远程连接,TCP/IP 已启用,服务器已启动,我可以通过 SSMS 和 Linqpad 连接到它。
当我在本地 运行 应用程序访问本地数据库时,就会发生这种情况。我知道连接字符串有效,因为我可以使用 SSMS 中的登录名进行登录,并且我有一个 linqpad 查询,使用相同的连接字符串可以正常工作。当我尝试打开连接时也会出现错误(即连接创建成功)。
我猜我的 IIS 配置有一些 access/security 问题,但我没有找到。
经过令人沮丧的几天后,我找到了解决方案。问题是 SQL 服务器未设置为使用 TCP/IP。这是在 Sql 服务器配置管理器中配置的,在 SQL 服务器网络配置节点下,然后是 MSSQLSERVER 的协议。确保 TCP/IP 已启用。
我有一个连接到 SQL Server 2012 数据库的 Web 表单应用程序。当我尝试在应用程序中打开连接时出现此错误:
System.Data.SqlClient.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 - No connection could be made because the target machine actively refused it.) ---> ...
我已经检查 SQL 服务器配置为允许远程连接,TCP/IP 已启用,服务器已启动,我可以通过 SSMS 和 Linqpad 连接到它。
当我在本地 运行 应用程序访问本地数据库时,就会发生这种情况。我知道连接字符串有效,因为我可以使用 SSMS 中的登录名进行登录,并且我有一个 linqpad 查询,使用相同的连接字符串可以正常工作。当我尝试打开连接时也会出现错误(即连接创建成功)。
我猜我的 IIS 配置有一些 access/security 问题,但我没有找到。
经过令人沮丧的几天后,我找到了解决方案。问题是 SQL 服务器未设置为使用 TCP/IP。这是在 Sql 服务器配置管理器中配置的,在 SQL 服务器网络配置节点下,然后是 MSSQLSERVER 的协议。确保 TCP/IP 已启用。