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
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)
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<!-- to profit from features in 2012, use its dialect -->
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<!-- the simplest connection string -->
<property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Database=rafal;Trusted_Connection=True;</property>
We have to be sure that correct driver is used (not CE or any other then NHibernate.Driver.SqlClientDriver
which means System.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With