Click to See Complete Forum and Search --> : Could not open a connection to SQL Server


kodekracker
05-18-2007, 10:05 AM
when using this connection string
SqlConnection thisSQLconnection = new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;Initial Catalog=northwind");

i get this error,

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)

what is wrong? how can i correct this?

Phil Weber
05-18-2007, 10:15 AM
Are you using SQL Server Express? By default, it installs a named instance; try changing the Data Source from "(local)" to ".\SQLEXPRESS".

kodekracker
05-18-2007, 10:18 AM
thanks its working now

by installing sqlserver without an instance name i can use the (local) or (server) variable ??

coding2005
05-24-2007, 02:00 AM
Hi,

You're right, if you install the SQL Server as default instance you can connect to it as (localhost) or the server name as well as the ip address. But SQL Server 2005 Express edition installs itself as a named instance with instance name "SQLEXPRESS" so you have to use ".\SQLEXPRESS" or "localhost\SQLExpress", etc. in order to connect to Express edition.

You can also refer to http://www.kodyaz.com/content/SQLServerdoesnotallowremoteconnections.aspx if remote connection is not allowed on the sql server and to use Surface Area Configuration tool to allow remote connections.

kodekracker
05-24-2007, 09:58 AM
thanks