views:

424

answers:

3

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>
A: 

Is your connection string correct?

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

Michael
does it look wrong? it should be correct. and even though i tried other formats still same crap.
+2  A: 

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."

haarrrgh
i have tried all these crap,nothing worked. i guess hibernate doesnt work :)
What does "nothing worked" mean? Did you try to connect to the database with pure ADO.NET with the same connection string, and did it work? If no, then it can't be a NHibernate problem.
haarrrgh
ADO.NET works. Hibernate doesnt wanna work.
I enable TCP/IP, VIA, names pipes etc. but still didnt work.
+2  A: 

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

Jaguar
THanks man, i tried this format, didnt wanna work. but ADO.NET works.