Friday, February 24, 2012

Connection String Problem

Hi guys,
I was trying to access the northwind database by using the following codes:

conn =new SqlConnection("data source=localhost;integrated security=true;initial catalog=Northwind");daCustomers =new SqlDataAdapter("select CustomerID, CompanyName from Customers", conn);
ds =new DataSet();
daCustomers.Fill(ds,"Customers");
When I preview the aspx, I would fail with the following error:

SQL Server does not exist or access denied.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.

Source Error:

Line 44: daCustomers = new SqlDataAdapter("select CustomerID, CompanyName from Customers", conn);Line 45: ds = new DataSet();Line 46: daCustomers.Fill(ds, "Customers");Line 47: Line 48: //create the second DataTable

But now the strange thing is when I change the data source to (local):

conn =new SqlConnection("data source=(local);integrated security=true;initial catalog=Northwind");

It works! So my question is why would localhost fail while (local) works? Shouldn't these 2 be the same? Thanks in advance.

Silvertype:

It works! So my question is why would localhost fail while (local) works? Shouldn't these 2 be the same? Thanks in advance.

I always use (local) as the server name. As far as I understand it, ifyou want to use localhost then SQL Server needs to be configured to usea TCP/IP protocol, which isn't always the case.|||

I see. Btw, how do I configure SQL Server to use TCP/IP?

|||

Silvertype:

I see. Btw, how do I configure SQL Server to use TCP/IP?


As far as I know, it's via:Start -> Programs -> Microsoft SQL Server -> Client Network Utility|||Well, it seems like TCP/IP is already enabled for my sql server. However, localhost is still not working. Any idea?|||

Silvertype:

Well, it seems like TCP/IP is already enabled for my sql server. However, localhost is still not working. Any idea?


I do not know for sure. I always use (local).

Check out this blog post from Jon Galloway for some possible further help/explanation:[tip] localhost vs. (local) in SQL|||

Ok, thanks.

No comments:

Post a Comment