[英]Need help configuring SQL Server CE connections string in Fluent NHibernate
我正在嘗試使用以下代碼返回會話工廠:
return Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(path))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
.BuildSessionFactory();
路徑是.sdf文件的完整路徑。
並獲得此異常:
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
at System.Data.SqlServerCe.ConStringUtil.GetKeyValuePair(Char[] connectionString, Int32 currentPosition, String& key, Char[] valuebuf, Int32& vallength, Boolean& isempty)
我究竟做錯了什么?
http://connectionstrings.com/sql-server-2005-ce
我以前從未使用過sdf,但是我的猜測是嘗試這樣的事情。 您必須使用有效的連接字符串,並且僅提供路徑不是有效的連接字符串。
Data Source=C:\mydatabase.sdf;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
將其傳遞而不是路徑。 理想情況下,這將來自配置文件中的“連接字符串”部分。
解決方法如下:
return Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(c => c.Is("data source=" + path)))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
.BuildSessionFactory();
此處來源: http : //marekblotny.blogspot.com/2009/02/fluentconfiguration-new-api-to.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.