3
votes

I've been trying to connect to SQL Server 2005 on my localhost and I can not connect...

Server name: (local)\SQLEXPRESS
Authentication: Windows Authentication

other Server name I have tried are

LOCALHOST\SQLEXPRESS
(local)\my local hostname

I get this error message:

Cannot connect to 127.0.0.1\SQLEXPRESS.
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.

SQL Server Browser is turned on in Services

any ideas?

3
Are you sure the SQL Server service is running? Are you sure it's a named instance called SQLEXPRESS? Have you tried 127.0.0.1\SQLEXPRESS? Can you show the actual error message you receive? Have you gone through these steps? blogs.msdn.com/b/sql_protocols/archive/2007/05/13/…Aaron Bertrand
TITLE: Connect to Server ------------------------------ Cannot connect to 127.0.0.1\SQLEXPRESS. ------------------------------ ADDITIONAL INFORMATION: 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: SQL Network Interfaces, error: 28 - Server doesn't support requested protocol) (Microsoft SQL Server, Error: -1)user979331
So the SQL Server Browse service is running but is the SQL Server service itself running?Martin Wilson

3 Answers

20
votes

(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".

0
votes

If You have installed VS2008 then re-install sqlexpress2005 part once more or additionally you need to install that one then it will automatically fix its server name.

0
votes

Make sure you have enabled the client protocols using the SQL Server Configuration Manager.