我正在开发一个 .net 项目,我第一次使用 SQL Server 2012 和流畅的 nhibernate,当我运行我的项目时,我收到以下错误 =>
Value cannot be null.
Parameter name: Data Source
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: Data Source
我的配置语法
Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2012.ConnectionString(c => c.FromAppSetting("ConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
.CurrentSessionContext<T>()
.BuildSessionFactory();
和我在 web.config
中的连接字符串:
<connectionStrings>
<add name="ConnectionString"
connectionString="Data Source=localhost; Initial Catalog=ExcelReport; Integrated Security=true;"
providerName="System.Data.SqlClient" />
</connectionStrings>
我尝试了各种方法,但无法解决问题。你有什么建议吗?
最佳答案
<connectionStrings>
与 <appSettings>
不同.
您的连接字符串不在应用程序设置中。
您的连接字符串在 <connectionStrings>
中
因此您需要使用 FromConnectionStringWithKey
而不是 FromAppSetting
.
例如:
c => c.FromConnectionStringWithKey("ConnectionString")
你的配置语法应该是:
Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2012.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
.CurrentSessionContext<T>()
.BuildSessionFactory();
关于c# - 流利的 NHibernate SQL Server 2012,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26318769/