简体   繁体   中英

SQL Server was not found or was not accessible

What is the problem below?

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)

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.Data.SqlClient.SqlException: 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)

How can this be solved?

所有程序>> Microsoft SQL Server 2008 >> 配置工具>> SQL Server 配置管理器>> SQL Server 服务,然后检查SQL Server 服务状态是否为“正在运行”。

Seeing as this result is second in Google when searching for:

Server is not found or not accessible

I'll add to this post. Colleague of mine has search for an entire day on this problem, checking his connection string and double checking his code. He could connect to the server using SQL but his application wouldn't connect.

Turns out he was running his application from a network share. Network shares only have partial trust and will produce this misleading exception as a result.

Move the project to your local drive and try again. Hope this helps someone!

You need to restart the MS SQL service. Please follow these steps:

1- Press window sign + R to open Run Window.

2- Type services.msc and press Enter.

3- Look for SQLSERVER(MSSQLSERVER) in the services list.

4- Right click on that service and choose REFRESH or START.

Hopefully it works.

This means pretty much exactly what it says. For some reason the computer the code was running on could not communicate with the SQL Server. This could be caused by a lot of things: Firewall issues, DNS/Name resolution, SQL Configuration (not configured to accept TCP/IP connection). Just to name a few.

We were getting this intermittently on our .NET website which accesses an SQL Server database on another server. I tried several things, including making sure I was closing all SQLConnections and recycling applications pools more frequently. These helped some but the problem still occurred from time to time. What it turned out to be was a DNS issue.

I resolved it by changing the connection string Data Source value from a domain name to an IP address , eg from:

Data Source=My-SQL-Server;Initial Catalog=database-name;Integrated Security=true

to

Data Source=10.1.2.237;Initial Catalog=database-name;Integrated Security=true

Just go through following steps:

  1. All Programs
  2. Microsoft SQL Server 2008 R2
  3. Configuration Tool
  4. SQL Server Configuration Manager
  5. A pop up will open click on yes.
  6. Select Sql Server Services (At left side) and Make sure status is running for all services (At right Side)

I was trying to run the MVC Movie tutorial but I had the error in question. So I created a new MVC project and copied its connection string and used that to replace the one in the tutorial. Basically, replace this:

Data Source=(LocalDB)\v11.0

With this:

Data Source=(LocalDb)\MSSQLLocalDB

For all connectionString properties.

One thing you can try is to open server explorer in Visual Studio.
Click Connect to database.
The datasource will be Microsoft SQL Server Database file. Click ok
Type in the Database file name or click Browse...
Click Test Connection and make sure it works.
If it does...click on the Advanced.. button.
Copy the Data Source text at the botton of the screen.

Almost everytime I see this error I was trying to use an instance name something like "long_pc_name/MSSQLExpress" (this is what shows up in MSSMS) And every time it just needs to be " (LocalDB)\\MSSQLLocalDB ".

If your connection string is pointing to a local db...

connectionString="Data Source=(localdb)\

Server=localhost\SQLEXPRESS;Database=

Another cause of this error is: you might not have Sql Server installed in your system.

Download Sql Server Express here:

https://www.microsoft.com/en-us/download/details.aspx?id=55994

Install it and try again.

You can use this connection string to connect to it:

Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;

Your local server name is localhost\\SQLEXPRESS.

Replace database with your database name.

Refer to this post if you still have trouble connecting:

Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?

Go to SSMS and check if the SQL server is accessible there. Try to replace domain name by IP address. Check if you have sufficient authorization,and other requirements fulfilled.

Try to check LAN connection and VPN connection, if required.

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