How to write correct connection string for Nhibernate using SQL Server 2012?
Should I write also database name?
Error:
I get error with wrong „initial catalog”
Wrong connection string for NHibernate (I copy this connection string from my server):
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Initial Catalog=rafal;Integrated Security=True</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
I copy connection string from this part:
I am trying also this but does not help.
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Initial Catalog=rafal;Integrated Security=True</property>
I don`t know how correct configure for SQL Server 2012
Best Answer
The first snippet should not work, while the driver is for CE (Compact edition).
The second one looks better, and even more it is working for me. (see more here http://www.connectionstrings.com/sql-server-2012). The most important thing, is to have correct settings of the Provider name (check here: https://stackoverflow.com/a/8150792/315850). Try this adjusted snippet (just to be sure that all parts are set correctly)
We have to be sure that correct driver is used (not CE or any other then
NHibernate.Driver.SqlClientDriver
which meansSystem.Data.SqlClient
)Double check that your 1) SQL server and named instance is:
RAFAL-KOMPUTER\MSSQLSERVER4
and 2) the Database name is:rafal
and 3) your login has access rights to it, this must work