nHibernate和SQL Server 2012 LocalDB [英] nHibernate and SQL Server 2012 LocalDB

查看:104
本文介绍了nHibernate和SQL Server 2012 LocalDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在NHibernate中使用LocalDB数据库?如果是,应该安装/配置什么?

Is it possible to use LocalDB databases with NHibernate? If yes, what should be installed/configured?

当前在创建SessionFactory时尝试使用连接字符串如 Data Source =(LocalDb)\ v11.0; Initial Catalog = tst1; Integrated Security = SSPI

Currently when trying to use connection string like Data Source=(LocalDb)\v11.0;Initial Catalog=tst1;Integrated Security=SSPI when creating SessionFactory I get

System.Data.SqlClient.SqlException:与网络相关或 建立与以下对象的连接时发生特定于实例的错误 SQL Server.服务器未找到或无法访问.核实 实例名称正确并且已将SQL Server配置为 允许远程连接. (提供者:命名管道提供者,错误:40- 无法打开与SQL Server的连接)----> System.ComponentModel.Win32Exception:找不到网络路径

System.Data.SqlClient.SqlException : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ----> System.ComponentModel.Win32Exception : The network path was not found

但是,我能够通过SQL Server Object Explorer连接到(LocalDb)\ v11.0 ,并且Entity Framework可以使用该连接字符串. 那么,我对NH有什么问题,还是目前无法在NH中使用LocalDB?

However, I'm able to connect to (LocalDb)\v11.0 via SQL Server Object Explorer, and Entity Framework works with that connection string. So, what am I doing wrong with NH, or it's impossible to use LocalDB with NH at the moment?

推荐答案

您可能必须对nH使用原始语法,例如:

You might have to use the archaic syntax with nH, e.g.:

np:\\.\pipe\LOCALDB#ABB78D50\tsql\query

(有关为何有时对于连接字符串有时需要使用此语法的某些背景知识,请参见

(For some background on why this syntax is sometimes required for connection strings, see this tip on mssqltips.com.)

我意识到这不是一个理想的答案,但是在nHibernate更新为正式支持SqlLocalDb之前,这可能是您唯一的选择……希望我做错了,并且有人找到了一种更优雅的连接方式.

I realize this isn't an ideal answer, but until nHibernate updates to officially support SqlLocalDb, it might be your only choice... hopefully I'm wrong and someone has figured out a more elegant way to connect.

这篇关于nHibernate和SQL Server 2012 LocalDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆