开发者

cannot connect to local database when network is down

开发者 https://www.devze.com 2023-03-10 05:18 出处:网络
I am using following connection string to connect to database on local machine. Problem is that if network goes down then i cannot connect to my database although application is connecting to database

I am using following connection string to connect to database on local machine. Problem is that if network goes down then i cannot connect to my database although application is connecting to database on same machine. What am I doing wrong?

add name="MainDb" connectionString="Data Source=MyComputerName,1433;Network Library=DBMSSOCN;Initial catalog=MyLocalDatabase;Integrated Security=False;Us开发者_JAVA技巧er=MyUser;Password=MyPassword;"


Use localhost as your computer name. localhost uses a shared memory connection, rather than climbing through the network layer.

Also verify, with sql server configuration manager, that shared memory is enabled.


Try to remove Network Library parameter from connection string. This way you are forcing the connection provider to use specific protocol. If you disable networking (TCP), it may be that the provider is not able to connect.

Here's some info about Network Library parameter http://support.microsoft.com/kb/238949

If the Network Library is not provided, application uses protocols in order specified in the SQL Server Configuration Manager, in SQL Native Client 10.0 Configuration, in node Client Protocols. These protocols must be of course enabled on the server side, which in case of the same machine is just located in the SQL Server Network Configuration, in Protocols.

I am using SQL Server 2008 R2, if you are using older, the version of the provider may be different.

Here is a question that looks to be concerned about similar issue:

SQL Server communication protocol issue

Regards

Piotr


When using DBMSSOCN, try supplying the IP address of the database instance, instead of MyComputerName. As @Dalen suggested, 127.0.0.1

http://www.connectionstrings.com/sql-server

Confirm also what port the instance is running on (usually 1433) and supply that after the IP address:

 Data Source=127.0.0.1,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
0

精彩评论

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

关注公众号