繁体   English   中英

无法从ASP.NET C#页连接到SQL Server 2005 Express

[英]Can't connect to SQL Server 2005 Express from an ASP.NET C# page

我在VPS上运行了MS SQL Server 2005 Express。 我在Python中使用pymssql通过以下代码连接到服务器:

conn = pymssql.connect(host='host:port', user='me', password='pwd', database='db')

而且效果很好。 当我尝试使用以下代码从ASP.NET C#页连接到服务器时:

SqlConnection myConnection = new SqlConnection("Data Source=host,port;Network Library=DBMSSOCN; Initial Catalog=db;User ID=me;Password=pwd;");

myConnection.Open();

当我运行ASP.NET页时,在myConnection.Open();处收到以下异常:

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 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

我尝试重新启动SQL Server,但是没有运气。 谁能指出我在这里想念的东西吗?

谢谢!

假设您的主机是本地主机。 使用SQLEXPRESS时,需要在实例名称中指定。

对此:如果Data Source=localhost\\SQLEXPRESS绑定到本地主机,则为: 否则,它可能只适用于: Data Source=.\\SQLEXPRESS

如果您安装了Management Studio,则可以启动并检查它使用的连接字符串!

仍然无法正常工作。我可以使用SQL Management Studio连接到远程服务器。 我在“服务器名称”字段中输入host,port \\ SQLEXPRESS(当然,我的实际IP地址为主机和我的实际端口),选择SQL Security,然后输入我的用户名和密码,即可正常运行。 当我尝试从ASP.NET页进行连接时,它不起作用-我收到了上述错误。 它与托管我的asp.net页的公司有关系吗? (GoDaddy)再次是代码。(假设我的主机是11.22.33.44,并且我的数据库名为bla

string connectString = @"Data Source=11.22.33.44,1433\SQLEXPRESS;Network Library=DBMSSOCN;Initial Catalog=bla;User ID=username;Password=pwd;";
SqlConnection myConnection = new SqlConnection(connectString);
myConnection.Open();

再次感谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM