简体   繁体   中英

Connection to SQL database failed.

With my windows service application I am trying to connect 2 databases called db1 and db2. Both db db1 and db2 are present in one SQL server.

I am able to connect db1 using service and fetch required details but I am getting below error while connecting db2

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I guess this issue may be because of db/server name is incorrect in connection string while connecting to db2. This is working fine in development environment but not in live.
Is there any way so that we can find out what db/server name it is trying to connect without debugging. Is there anything like error logs for sql which will capture during connection?

Verify your firewall settings. The default port is TCP 1433. To rule out the firewall you may disable/enable it, and try to connect.

Use SQL Server Configuration Manager and verify the services are running.

First try to test connection the mentioned database from your application. I think the issue is because of your login credentials. Please verify first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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