简体   繁体   English

错误的连接字符串NHibernate 3.3

[英]Wrong connection string NHibernate 3.3

How to write correct connection string for Nhibernate using SQL Server 2012? 如何使用SQL Server 2012为Nhibernate编写正确的连接字符串?

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): NHibernate的连接字符串错误(我从我的服务器复制此连接字符串):

<?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 我不知道如何正确配置SQL Server 2012

The first snippet should not work, while the driver is for CE (Compact edition). 第一个代码段不起作用,而驱动程序适用于CE(精简版)。

The second one looks better, and even more it is working for me. 第二个看起来更好,甚至更多它对我有用。 (see more here http://www.connectionstrings.com/sql-server-2012 ). (更多信息请参见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 ). 最重要的是,要正确设置提供商名称(请在此处查看: 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 ) 我们必须确保使用正确的驱动程序(不是CE或任何其他NHibernate.Driver.SqlClientDriver ,这意味着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 仔细检查你的1)SQL服务器和命名实例是: RAFAL-KOMPUTER\\MSSQLSERVER4和2)数据库名称是: rafal和3)你的登录有访问权限,这必须工作

just replace : SqlServerCeDriver by SqlClientDriver as below : 只需用SqlClientDriver替换: SqlServerCeDriver ,如下所示:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM