如何使用 SQL Server 2012 为 Nhibernate 编写正确的连接字符串?
我还应该写数据库名称吗?
错误: 我收到错误的“初始目录”错误
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>
我从这部分复制连接字符串:
我也在尝试这个,但没有帮助。
<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>
我不知道如何正确配置 SQL Server 2012
最佳答案
第一个片段应该不起作用,而驱动程序是用于 CE(精简版)的。
第二个看起来更好,甚至更适合我。 (在此处查看更多信息 http://www.connectionstrings.com/sql-server-2012 )。最重要的是正确设置提供者名称(检查此处:https://stackoverflow.com/a/8150792/315850)。试试这个调整后的片段(只是为了确保所有部分都设置正确)
<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>
我们必须确保使用了正确的驱动程序(不是 CE 或任何其他 NHibernate.Driver.SqlClientDriver
,这意味着 System.Data.SqlClient
)
仔细检查您的 1) SQL 服务器和命名实例是:RAFAL-KOMPUTER\MSSQLSERVER4
和 2) 数据库名称是:rafal
和 3) 您的登录名是访问权限,这必须有效
关于c# - 错误的连接字符串 NHibernate 3.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15043161/