Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate is not connecting to sql server

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

Message="A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)" Source=".Net SqlClient Data Provider"

What would be the reason for this and how can i resolve it ?

I doubt that it s 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>
like image 700
DarthVader Avatar asked Mar 24 '10 14:03

DarthVader


3 Answers

Try to connect to the server with the same connection string, but with another data access technology, for example pure ADO.NET.

If that fails as well, then it's not a NHibernate problem.
Maybe your connection string or some SQL server settings are not correct, as indicated in the error message:

"Verify that the instance name is correct and that SQL Server is configured to allow remote connections."

like image 152
Christian Specht Avatar answered Sep 25 '22 17:09

Christian Specht


Is your connection string correct?

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

like image 25
Michael Avatar answered Sep 23 '22 17:09

Michael


This is the format i have used for over a dozen applications for SQL SERVER 2005/2008

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

or if you require an instance name

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

replace the placeholders in capital letters. Also ensure that you have set up sql-server to allow connections for Sql Server Authentication and not only Windows Authentication. Check your firewall as well

like image 26
Jaguar Avatar answered Sep 24 '22 17:09

Jaguar