简体   繁体   English

未找到或无法访问 SQL Server

[英]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:只需执行以下步骤:

  1. All Programs所有程序
  2. Microsoft SQL Server 2008 R2微软 SQL Server 2008 R2
  3. Configuration Tool配置工具
  4. SQL Server Configuration Manager SQL Server 配置管理器
  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)选择Sql Server 服务(左侧)并确保所有服务的状态都在运行(右侧)

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.

相关问题 SQL Server未找到服务器或无法访问服务器 - SQL Server The server was not found or was not accessible 找不到或无法访问Asp.net SQL Server实例 - Asp.net SQL server instance not found or not accessible 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 找不到我的服务器或无法访问我的服务器 - A network-related or instance-specific error occurred while establishing a connection to SQL Server. My server was not found or was not accessible 使SQL Server 2005可通过Internet访问 - Make SQL Server 2005 accessible via Internet 为什么我会间歇性地得到这个错误? “服务器未找到或无法访问” - Why would I get this error intermittently? “The server was not found or was not accessible” 无法从托管的ASP.NET应用访问SQL Server - SQL Server not accessible from hosted ASP.NET app SQL配置文件给服务器找不到异常 - SQL Profile giving server not found exception 创建存储在公司网络上SQL Server 2008 R2上的可访问ASP内部网页面 - Creating an accessible ASP intranet page stored on SQL Server 2008 R2 on Corporate Network 指定协议和端口时,只能在ASP.NET 1.1中访问Sql Server 2005 - Sql Server 2005 only accessible in ASP.NET 1.1 when I specify protocol and port 只有首先使用RDP才能访问URL时访问SQL Reports服务器 - Accessing SQL Reports server when url is only accessible by first using RDP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM