3

我一直在尝试在我的本地主机上连接到 SQL Server 2005,但我无法连接......

服务器名称:(本地)\SQLEXPRESS
身份验证:Windows 身份验证

我尝试过的其他服务器名称是

LOCALHOST\SQLEXPRESS
(本地)\我的本地主机名

我收到此错误消息:

无法连接到 127.0.0.1\SQLEXPRESS。
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。

SQL Server Browser 在服务中打开

有任何想法吗?

4

3 回答 3

20

(1)

You need to verify (not just guess) that the SQL Server service is running. You can do this by going to Start > Control Panel > Administrative Tools > Services, and checking that the service SQL Server (SQLEXPRESS) is running. If not, start it.

(2)

While you're in the services applet, also make sure that the service SQL Browser is started. If not, start it.

(3)

You need to make sure that SQL Server is allowed to use TCP/IP or named pipes. You can turn these on by opening the SQL Server Configuration Manager (found under Start > Programs > Microsoft SQL Server 2005 > Configuration Tools), and make sure that TCP/IP and Named Pipes are enabled. Here my instance name is different but you can see that both of these protocols are disabled (you'll want to check under Protocols for SQLEXPRESS):

enter image description here

(You'll need to restart the SQL Server service if you change these settings.)

(4)

While it is no longer used in current versions of SQL Server, you'll also want to check the Surface Area Configuration tool. This is also found under Start > Programs > Microsoft SQL Server 2005 > Configuration Tools. Click on "Surface Area Configuration for Services and Connections", then highlight SQLEXPRESS (again my local instance name is SQL2005 but pretend it's the same as yours), and under Database Engine > Remote Connections, enable "Local and remote connections" for the option "Using both TCP/IP and named pipes." In the screen shot below I only have TCP/IP enabled. If you change these settings, hit Apply, and again you'll need to restart SQL Server for the changes to take effect.

enter image description here

(This won't help your current problem but you may need to enable this if you want to connect to SQL Server from other machines, and it may also help future readers who are trying to connect to SQL Server 2005 remotely.)

(5)

It may also help to shut off Windows Firewall temporarily, in case you are blocking yourself somehow. (Control Panel > Windows Firewall)

(6)

Review SQL Server's error log. You can get to this file at a path something like:

C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\

(I don't have an Express instance handy so the path might be slightly different on your machine.)

Now, in that folder there will be a file called ERRORLOG... this is the most recent log file that was generated the last time SQL Server started. You can right-click this file and choose Open With... select notepad. You should see some lines like this:

2012-05... Authentication mode is MIXED.
...
2012-05...
Server name is 'something\SQLEXPRESS'. This is an informational message only. No user action is required.
...
2012-05... Server local connection provider is ready to accept connection on [ \.\pipe\SQLLocal\SQLEXPRESS ].
2012-05... Server local connection provider is ready to accept connection on [ \.\pipe\MSSQL$SQLEXPRESS\sql\query ].
2012-05... Server is listening on [ ::1 49164].
2012-05... Server is listening on [ 127.0.0.1 49164].
...
2012-05... SQL Server is now ready for client connections. This is an informational message; no user action is required.

Please tell us which of these lines you don't see, and what the second line says where I wrote "something\SQLEXPRESS".

于 2012-05-16T19:24:21.373 回答
0

如果您已经安装了 VS2008,则再次重新安装 sqlexpress2005 部分,或者您需要另外安装该部分,然后它将自动修复其服务器名称。

于 2013-03-15T19:47:34.130 回答
0

确保您已使用 SQL Server 配置管理器启用客户端协议。

于 2014-02-22T20:03:12.257 回答