48

I'm using SQL Server 2008 and in Visual Studio, in Server Explorer, I can connect to SQL Server running using my computer name, but I can't using 127.0.0.1 or localhost, shouldn't they be the same?

Also when using a connection string in the web.config file for the website I can't connect using localhost, but only with the computer name! Is there some setting I'm missing somewhere in the SQL Config Manager?

  • 4
    David, I know its been years, but did you get a solution to this problem? I've come across the exactly same issue and am unable to find a solution to this problem :| – texens Apr 24 '12 at 15:25
  • Maybe a stupid question, but isn't it able to use named pipes for local? So maybe, something about networking isn't set up (see yam's answer), but when you go by name, it uses named pipes, which makes your troubleshooter's mind go nuts because it was thinking networking _was_ set up right. – FastAl May 07 '13 at 19:37

5 Answers5

87

If someone followed this post and still hasn't solved their problems (like me), here's what solved it for me:

Step 1: I went to the TCP/IP line in SQL Server Network Configuration, under Protocols for SQLEXPRESS (though you should select your active sql server) and clicked on properties:

enter image description here

Step 2: Then, I made sure that under IP Addresses, the group IP4 is Enabled = "Yes", and that the TCP Port in there is set to 1433 (the default sql server port), like here:

enter image description here

Step 3: Lastly, just as a precaution, I've changed all the other IP group ports to 1433 also, and enabled = "Yes" them from IP2 to IP5 (I saw this one at another computer). I've also changed the IPAll's (the last group) TCP Port to 1433 as well. But that's just me. I'm crazy. Go crazy. It's good for you. Last, make sure Enabled is set to Yes on the protocol tab as well.


and then - Hooray! it worked. Cheers for all the good-hearted people that take their time to solve other people's problems.

dallin
  • 8,775
  • 2
  • 36
  • 41
Yam Tal
  • 871
  • 6
  • 3
19

You probably need to set Sql Server to allow "remote" connections:

  1. Go to Start > All Programs > Microsoft Sql Server 2008 > Configuration Tools > Sql Server Configuration Manager
  2. When the configuration manager has loaded, expand the "SQL Server Network Configuration" node of the treeview to the left
  3. Select the Sql Server instance that you're trying to connect to in the tree
  4. All three of "Shared Memory", "Named Pipes" and "TCP/IP" should show as Enabled in the list to the right. For any that don't, double click each one in turn and change Disabled to Enabled in the window that appears.
  5. Click on "Sql Server Services" in the treeview
  6. Choose "SQL Server (InstanceName)" (where InstanceName will probably be SqlExpress or MsSqlServer), right click and choose Restart

Once the restart has completed, try connecting again - it should work now.

Rob
  • 45,296
  • 24
  • 122
  • 150
  • 1
    Hi Rob, thanks but they are already enabled. It throws an error now even when using my computer name! I just reinstalled SQL 2008 on a different machine and says COMPUTER92/SQLSERVER can not login to database "mdbb" (computer 92 is my computer name, its is a valid Login under the server security -> logins, and it says its mapped to "mdbb" but under the users it doesn't show COMPUTER92/SQLSERVER as a user of "mdbb" !! –  Aug 27 '09 at 10:23
9

Use localhost\sql_server_instance_name

For example, localhost\sqlexpress

Use . instead of 127.0.0.1

.\sqlexpress

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • 1
    The OP has said that it works with the machine name but not with "localhost" or the IP address, but didn't mention any instance name.. – Rob Aug 27 '09 at 09:39
5

You can also try: .\sql_server_instance_name

.\SQLExpress
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
  • great solution. this makes it easy to run projects on various computers with local instances of a test database. – Anthony Aug 21 '14 at 04:25
0

I had the same problem, and it looks like there were two issues.

First was implementing Rob's advice, ie to use the configuration manager to enable the SQL connections.

Second was to connnect to a specific instance, as advised by several folk. From the configuration manager I realised I had two instances, SQLEXPRESS and HOMEINSTALL. I could then make a connection using eg localhost\sqlexpress or .\homeintall.