Cannot connect to a named instance

Topics: Data Access Application Block
Dec 27, 2006 at 3:34 PM
Hi!

I have a problem with SqlServer 2K named instance connection from EntLib 05.
What amaze me me a lot that if i do it using SqlConnection directly everyting words just fine.

I able to connect using isql without any additional efforts.
To be able connect using SqlConnection directly I created server alias.

But i cannot connect anyway with EntLib despite the fact that connection string looks fine. Following is error 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 wonder why it says server is 2005?

Any help will be appreciated! Please!

Dec 27, 2006 at 9:17 PM
I would need more information about the connection string in your configuration file, but if you can connect to it directly using SqlDatabase via its constructor:

SqlDatabase(string connectionString)

The only thing done differently using DatabaseFactory.CreateDatabase(string namedInstance)

is that you need to set the proper provider as part of the connection string:

<connectionStrings>
<add name="..." provider="System.Data.SqlClient" />
</connectionString>

It is the provider="System.Data.SqlClient" that tells the DAAB to invoke the SqlDatabase Class.

I would make sure the provider name is correct. If you still have problems, please provide more information about your connectionString Configuration Section as well as the code invoking the named instance.

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#
http://www.davidhayden.com/
Dec 28, 2006 at 1:08 AM
I have seen this problem if you forget to copy dataConfiguration.config to the output directory.
Dec 28, 2006 at 6:33 PM
Good point.

When using SqlDatabase Directly, you can just pass it a connection string as I show above and you don't need any configuration in your app.config and web.config.

However, when you start using the DatabaseFactory Class, it needs configuration information to know what database to connect to, etc., which is why I mention the need for connection strings.

Here is a quick intro on my website for configuring the DAAB

http://davidhayden.com/blog/dave/archive/2006/01/23/2744.aspx

I recommend going over the quickstart tutorials that come with Enterprise Library as well.

Regards,

Dave

______________________

David Hayden
Microsoft MVP C#
http://www.davidhayden.com/