[英]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.
与 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.
验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)
Description: An unhandled exception occurred during the execution of the current web request.
说明:在执行当前 Web 请求期间发生未处理的异常。 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.
异常详细信息:System.Data.SqlClient.SqlException:建立与 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.
验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(提供程序:命名管道提供程序,错误:40 - 无法打开与 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.
他可以使用 SQL 连接到服务器,但他的应用程序无法连接。
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.您需要重新启动 MS SQL 服务。 Please follow these steps:
请按照以下步骤操作:
1- Press window sign + R to open Run Window. 1- 按窗口符号 + R 打开运行窗口。
2- Type services.msc and press Enter. 2- 键入 services.msc 并按 Enter。
3- Look for SQLSERVER(MSSQLSERVER) in the services list. 3- 在服务列表中查找 SQLSERVER(MSSQLSERVER)。
4- Right click on that service and choose REFRESH or START. 4- 右键单击该服务并选择刷新或开始。
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.
由于某种原因,运行代码的计算机无法与 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).
这可能是由很多原因引起的:防火墙问题、DNS/名称解析、SQL 配置(未配置为接受 TCP/IP 连接)。 Just to name a few.
仅举几个。
We were getting this intermittently on our .NET website which accesses an SQL Server database on another server.我们在访问另一台服务器上的 SQL Server 数据库的 .NET 网站上间歇性地得到这个。 I tried several things, including making sure I was closing all SQLConnections and recycling applications pools more frequently.
我尝试了几件事,包括确保更频繁地关闭所有 SQLConnections 和回收应用程序池。 These helped some but the problem still occurred from time to time.
这些帮助了一些,但问题仍然不时发生。 What it turned out to be was a DNS issue.
结果是DNS问题。
I resolved it by changing the connection string Data Source
value from a domain name to an IP address , eg from:我通过将连接字符串
Data Source
值从域名更改为IP 地址来解决它,例如:
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:只需执行以下步骤:
I was trying to run the MVC Movie tutorial but I had the error in question.我试图运行MVC 电影教程,但我遇到了有问题的错误。 So I created a new MVC project and copied its connection string and used that to replace the one in the tutorial.
所以我创建了一个新的 MVC 项目并复制了它的连接字符串并用它来替换教程中的那个。 Basically, replace this:
基本上,替换这个:
Data Source=(LocalDB)\v11.0
With this:有了这个:
Data Source=(LocalDb)\MSSQLLocalDB
For all connectionString
properties.对于所有
connectionString
属性。
One thing you can try is to open server explorer in Visual Studio.您可以尝试的一件事是在 Visual Studio 中打开服务器资源管理器。
Click Connect to database.单击连接到数据库。
The datasource will be Microsoft SQL Server Database file.数据源将是 Microsoft SQL Server 数据库文件。 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 ".几乎每次我看到这个错误时,我都试图使用类似“long_pc_name/MSSQLExpress”的实例名称(这是在 MSSMS 中显示的内容)并且每次只需要是“ (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.此错误的另一个原因是:您的系统中可能没有安装 Sql Server。
Download Sql Server Express here:在此处下载 Sql Server Express:
https://www.microsoft.com/en-us/download/details.aspx?id=55994 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.您的本地服务器名称是 localhost\\SQLEXPRESS。
Replace database with your database name.将 database 替换为您的数据库名称。
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.转到 SSMS 并检查 SQL 服务器是否可以在那里访问。 Try to replace domain name by IP address.
尝试用 IP 地址替换域名。 Check if you have sufficient authorization,and other requirements fulfilled.
检查您是否有足够的授权,并满足其他要求。
Try to check LAN connection and VPN connection, if required.如果需要,请尝试检查 LAN 连接和 VPN 连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.