NHibernate does not connect to sql server

When I set up a regular connection, it works, however, when I try to use nhibernate, hibernate.cfg.xml, I get the following error.

Message = "A network-related or specific instance error occurred while establishing a connection with SQL Server. The server was not found or is unavailable. Verify the instance name is correct and configure SQL Server for remote access (provider: SQL network interfaces, error: 26 - server location error / instance) "Source =" .NET SqlClient Data Provider "

What will be the reason for this and how can I solve it?

I doubt this is a network or sql server configuration error.

<?xml version="1.0" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > <session-factory> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string">Server=(ServerName\DEV_ENV);Initial Catalog=dbName;User Id=SA;Password=PASS</property> <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> 
+6
c # sql-server nhibernate connection
source share
4 answers

Try connecting to the server with the same connection string, but with a different data access technology, for example, with pure ADO.NET.

If this fails, then this is not a NHibernate problem.
Perhaps your connection string or some SQL server settings are incorrect, as indicated in the error message:

"Verify the instance name is correct and configure SQL Server for remote connections."

+2
source share

Is the connection string correct?

http://www.connectionstrings.com/sql-server-2005

+2
source share

This is the format that I have used for more than a dozen applications for SQL SERVER 2005/2008

 data source=COMPUTERNAME;User Id=USERNAME;Password=PASSWORD;database=DATABASENAME 

or if you need an instance name

 data source=COMPUTERNAME\SERVERINSTANCE;User Id=USERNAME;Password=PASSWORD;database=DATABASENAME 

replace placeholders with capital letters. Also make sure you configure the sql server to allow connections for Sql Server Authentication and not just Windows Authentication . Check your firewall as well

+2
source share

I wrote a small piece of code in the same application to open a raw ado.net connection with the same connection string, and it worked.

Then I copy this connection string to the configuration file for nhibernate, and it starts working.

When I compared the original line with the error message and the new connection line ... I could not see any difference ... I do not know what is happening ... completely dead end ... in any case, the problem is solved. hope this helps someone.

+2
source share

All Articles