Wrong connection string NHibernate 3.3

狂风中的少年 提交于 2019-12-08 17:11:48

问题


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


回答1:


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




回答2:


just replace : SqlServerCeDriver by SqlClientDriver as below :

Replace : <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>

By: <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>



来源:https://stackoverflow.com/questions/15043161/wrong-connection-string-nhibernate-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!