CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

Why localhost may not be a good sqlserver (Cannot generate SSPI context)

Setting up the asp.net forums app on my local XP pro machine took some puzzling. The setup proposes localhost as sqlserver. Running the app resulted in a Cannot generate SSPI context error. There is a MS support article on this HOW TO: Troubleshoot the "Cannot Generate SSPI Context" Error Message. This article is interesting but tries to cover to much. In my scenario it boiled down to sql server being unable to set up a trusted connection to Localhost.

This was the connectionstring (found in the web.config)

<add key="connectionString" value="server=localhost;Trusted_Connection=true;database=AspNetForums" />

Changing the server part of the connectionstring to the name of my machine

<add key="connectionString" value="server=MyComputer;Trusted_Connection=true;database=AspNetForums" />

resulted in a proper connection and got the app up and running

Peter


Comments

Peter van Ooijen said:

Trying to connect to the SQLserevr "LOCAL" is no guarantee for success. Using the actual name of the server (as seen in the VS.net server explore) does work.
# February 25, 2004 7:36 AM

Darrell said:

Yeah, I was just pointing out the correct way to use "local" versus "localhost". I always use the server name myself.
# February 25, 2004 10:07 AM

Peter van Ooijen said:

So do I. Well.. vs.net does so when I drop a connection on a componennt. This localhost thing was an idea of the asp.net forums project.
Most parts of it look excellent, but this is apparantly a little stupid :/
# February 25, 2004 12:31 PM

Enjoy Every Sandwich said:

In the bag tonight: Less bitch'n and whin'n. Counts:Blogging: 8; Dev: 22; Otherwise: 8; SQL: 5; WILY: 8. Line of the night:
# February 25, 2004 3:20 PM

Matej said:

Hi,

This is crazy. So so so many people have so many problems with "Cannot generate SSPI context" error and Microsoft still does nothing to solve it.
Matej
# June 9, 2004 9:15 AM

Ray said:

Possible Solution.

Hey guys, I found something that fixed my SSPI error. In the docs, it talks all about if this then SSPI, if that then NTLM. The ultimate result is that if Kerberos is being used, and the host name can't be resolved correctly, then the SPN isn't generated correctly and the whole thing fails.

Can't resolve host name? Check your DNS entry and/or add an entry into the hosts (c:\winnt\system32\drivers\etc\hosts) file on the machine that is trying to connect. This also caused my MS SQL Reporting Services connection problems to go away.

Hope this helps.

Ray
# June 28, 2004 10:18 PM

Simone Busoli Weblog said:

# December 2, 2005 5:13 AM

Andrei said:

I was trying to set up a system DSN for one of my clients and kept getting the error.
Adding the server to the host list solved the problem! Thx Ray!
# July 17, 2006 2:50 PM

PI said:

I am having a C++ app in which I connect to SQL Server 2000 database (Win2K3, SP1). I am using 'LOCALHOST' in the connection string. But when I use LOCALHOST, there is a problem of connection leak on SQL Server 2000. Lots of connections remain open through the C++ app. Now when I use '(LOCAL)' in the connection strings, the problem of connection leak goes away. Connections to SQL Server 2000 are closed properly and there is no connection leak on the machine (Wow....). Is it a problem of LOCALHOST? If yes, then what goes wrong while using LOCALHOST?

# January 10, 2007 12:01 AM

pvanooijen said:

Localhost is an IP address where to find the server. All communication goes over TCP at the address 127.0.0.1

Local is sql server specific. The communication will not use TCP but something like named pipes.

As it looks the different versions of your connectionstring lead to a different communication protocol between client and sql-server. Which leads to different behavior.

# January 10, 2007 10:51 AM

PI said:

But is there any specific reason to use '(local)' and not localhost in SQL Server connection strings? What makes its behaviour different when we use localhost and why do the connection leaks? The same application when run on SQL 2005 it does not leak the connections. So there is nothing wrong in the code but something related to SQL Server 2000.

# January 10, 2007 11:22 PM

pvanooijen said:

There us. Using Local you're requesting the server on the local machine. Using localhost you're requesting the server on the machine localhost. This is (usually) the local machine but you have to pass a lot of more stacks to get there. In your sql 2000 scenario something is not going right in the latter case. Don't ask me what; there are a lot of places.

# January 11, 2007 2:07 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!