开发者

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

开发者 https://www.devze.com 2022-12-31 04:24 出处:网络
I have an MS SQL Server 2005 Express running on a VPS. I\'m using pymssql in Python to connect to my server with the following code:

I have an MS SQL Server 2005 Express running on a VPS. I'm using pymssql in Python to connect to my server with the following code:

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

and it works perfectly. When I try to connect to the server from an ASP.NET C# page with the following code:

SqlConnection myConnection = new SqlConnection("Data Source=host,port;Network Library=DBMSSOCN; Initial 开发者_如何学运维Catalog=db;User ID=me;Password=pwd;");

myConnection.Open();

When I run the ASP.NET page I get the following exception at 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.)

I tried restarting the SQL Server but I had no luck. Can anyone point me out to what I'm missing here?

Thanks!


Let's say your host is localhost. When you are using SQLEXPRESS you need to specify that in your Instance Name.

Loke this: Data Source=localhost\SQLEXPRESS if it is bound to localhost. Otherwise it might just work with: Data Source=.\SQLEXPRESS.

If you have management studio installed you can fire that up and check what connection string it is using!


Still doesn't work.. I'm able to connect to the remote server with SQL Management Studio. I enter host,port\SQLEXPRESS (of course I my actual IP number as the host and my actual port) in the Server Name field, select SQL Security and enter my username and password and it works perfectly. When I try to connect from the ASP.NET page, it just doesn't work - I get the error aforementioned. Can it have something to do with the company hosting my asp.net page? (GoDaddy) here is the code again..(assuming my host is 11.22.33.44 and my db is named 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();

Thanks again

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号