2017-09-14 120 views
0

我正在使用一个使用SQL Server作为数据库的工具。从ASP.NET Web应用程序无法连接到我的SQL Server Express

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

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

我曾经尝试都连接远程,运行我的本地计算机上的网络应用程序,连接到tcp:{IP}\InstanceName,以及在连接字符串中使用.\InstanceName我VM IIS服务器上运行的应用程序(虽然我仍然可以告诉如果服务器设置正确处理TCP检查?)

在VM本地连接,使用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.)]

(及以上,但它似乎并不重要 - 会后,如果有必要或有益的)

任何想法,我做错了?

+0

您最好先检查此[链接](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/sql/virtual-machines-windows-sql-connect)。 –

+0

你告诉我:https://imgur.com/a/yJjJw。 Windows防火墙已被禁用(用于测试)以及配置为打开用于TCP的端口1433 – Vaethin

+0

我认为我完成了该链接中描述的所有内容,尽管门户网站中的我的虚拟机刀片看起来不同 - 没有SQL Server标签。这是因为我没有在Azure中进行设置,我只是在操作系统中手动安装了SQL Server Express。 – Vaethin

回答

0

找到了解决办法我自己:

这不是足以在服务器配置管理器中启用TCP,还需要SQL Server网络配置> X协议> TCP>属性> IP地址,并在IPAll下将TCP端口设置为1433。

0

SQL Server Express不允许远程连接 - 默认情况下。

您需要明确启用远程连接 - 最简单的方法是使用SQL Server Management Studio中,连接到它,然后在“对象资源管理器”上的服务器图标上单击右键,并选择“属性”。

在显示时,请务必的“允许远程连接到此服务器”复选框对话框:

enter image description here

+0

可惜不是问题,盒子已经打勾了...... – Vaethin

相关问题