Tuesday, March 27, 2012

Connecting to SQL Server (Local Machine)

Hi all,

Apologies if this is a dumb question, but I'm tearing my hair out over the basics when I should be spending time learning ASP.NET 2.0 and C#. I've searched the archives and a lot of people seem to be getting the same error as me, but when trying to connect from remote machines.

I'm getting what seems to be a standard message ...

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I'm not trying to connect remotely, I'm on my developer machine. The error comes up when trying to connect from within VS2005 (Tools, Connect to Database). It also comes up if I create a new web-site and go to the ASP.NET configuration tool (this is, I guess, trying to create the necessary database behind the scenes but is unable to connect to the database).

I suspect the error might be related to one or more of the following ...

September last year I installed VS2005 Express and SQL*SERVER Express. Both were fully un-installed when I bought VS2005 Professional before installing the new product.

When I set up SQL*SERVER 2005 Developer I remember choosing an option to have a separate user on my PC with administrative rights. Actually I don't recall much about what I chose but I can't find out where those permissions are managed from.

I've followed various instructions to check that remote access is enabled (despite the fact that I'm local, not remote). TCP and Named Pipes are both enabled (and I stopped then restarted SQL Server). I've checked that the service is started.

The odd thing is that I have had an application connect with the following string ...

SSLCon = new SqlConnection(@."Server=(local)\SSLMJ;Integrated Security = True;" + "Database=SSLTESTRESULTS");

Though the application connection seems to work ok, I think I'm missing out lots of developer functionality because I can't get VS2005 to see the database or server.

Help ?

Further info ...

I found and checked my machine.config file which has the following section ...

<connectionStrings>

<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />

</connectionStrings>

Could the reference to SQLEXPRESS be causing my problem ? How do I correct this ?

|||Tried commenting out the line beginning <add, but no effect.|||If you are connecting to the Express Edition instance on the same machine as it is running, you do NOT need to configure remote connections. Take a look at your services and see if the SQL Browser service is running. If it isn't running, start the service and try connecting again.|||

Thanks Michael. Using the Surface Area tool I've checked that the database engine and broswer are both running. Agent is not running. Remote Connections are set to both local and remote using both TCP and Named Pipes. However, I'm connecting locally (or trying to).

I'm using SQL Server 2005, not Express.

I don't understand why my application code can connect, but VS2005 can't ?

|||

Sorted - though I don't know why this worked.

Without changing any setup info ...

- went to configure my SqlDataSource as normal

- Instead of expanding the listbox for "Server Name" and finding it empty I typed the fully qualified name "MICKSPC\SSLMJ"

- expanded the list of database names - there they were !

I'd still like to know why VS couldn't find my server ? Any ideas ? "MicksPC" is there in Server Explorer. Expanding it shows the following ...

- Crystal Reports Services

- Event Logs

- Management Classes

- Management Events

- Message Queues

- Performance Counters

- Services

Under services is listed "SQL Server (SSLMJ)" and the properties for that service show it is running with a service name of MSSQL$SSLMJ.

No comments:

Post a Comment