2016-10-06 48 views
-1

我长期使用流利的nhibernate。它的工作正常,直到我更新我的数据库。在此之前,我使用SQL Server 2012,并更新到2016年时,试图在数据库应用程序连接,它抛出一个错误:在nhibernate中连接数据库时系统找不到文件

The system cannot find the file specified.

,当它试图连接。我的连接功能如下

Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ShowSql().ConnectionString(x=> x.FromConnectionStringWithKey("imConnectionString2"))).Mappings(m=> m.FluentMappings.AddFromAssemblyOf<MapUsers>()).BuildSessionFactory(); 

这在数据库更新前工作正常。我将MsSql2005更改为MsSql2012,但结果相同。

我需要在Fluent Nhibernate侧面或配置上做什么吗?

任何帮助,请

+0

添加完整的例外信息。 –

+0

如果你解决了问题,你能反馈吗? –

+0

感谢您的回复,但它不适合我,所以我恢复使用旧服务器 –

回答

0

有一个在客户端连接的SQL Server 2016 一个重大变化这种变化是由于SQL客户端已成为支持Windows和其他O.S如Linux。

安装Microsoft ODBC Driver 13 for SQL Server - Windows https://www.microsoft.com/en-us/download/details.aspx?id=50420

回顾:Installing SQL Server Native Client

SQL Server的本机客户端(SNAC),不支持超出了SQL Server的新的开发工作中使用SNAC 2012年避免,并计划目前修改应用程序用它。 Microsoft ODBC驱动程序的SQL Server提供从Windows本地连接到Microsoft SQL Server

在配置NHibernate的,通过使用SQLCMD工具,确保您可以与SQL Server 2016连接(用于服务器2016-下载)

更新:

当您安装名为msodbcsql.msi的驱动程序时,它确实是SQL 2012客户端的相同驱动程序。

我安装在视窗7(32位)的驱动程序,使用库FluentNHibernate v 2.0.3和连接到SQL服务器2016和成功运行以下代码:

class FluentNHibernateTest 
{ 
    private static ISessionFactory CreateSessionFactory() 
    { 
     //also MsSqlConfiguration.MsSql2005 is working 
     return Fluently.Configure() 
       .Database(
        MsSqlConfiguration.MsSql2012.ShowSql() 
         .ConnectionString(x => x.FromConnectionStringWithKey("test16"))) 
       .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>()) 
       .BuildSessionFactory(); 
    } 
    public static string GetSqlVersion() 
    { 
     string sql = "select @@version version"; 
     var sessionFactory = CreateSessionFactory(); 

     using (var session = sessionFactory.OpenSession()) 
     { 
      var query = session.CreateSQLQuery(sql); 
      var result = query.UniqueResult(); 
      Console.WriteLine(result); 

      return result.ToString(); 
     } 
    } 
} 

输出结果:

 FluentNHibernateTest.GetSqlVersion(); 

    Microsoft SQL Server 2016 (RTM-CU1) (KB3164674) - 13.0.2149.0 (X64) 
    Jul 11 2016 22:05:22 
    ....... 
相关问题