[英]Need help configuring SQL Server CE connections string in Fluent NHibernate
I'm trying to return a session factory using this code: 我正在尝试使用以下代码返回会话工厂:
return Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(path))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
.BuildSessionFactory();
Path is the full path to an .sdf file. 路径是.sdf文件的完整路径。
And get this exception: 并获得此异常:
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)
What am I doing wrong? 我究竟做错了什么?
http://connectionstrings.com/sql-server-2005-ce http://connectionstrings.com/sql-server-2005-ce
I've never used an sdf before, but my guess is to try something like this. 我以前从未使用过sdf,但是我的猜测是尝试这样的事情。 You have to use a valid connection string, and simply providing the path is not a valid connection string.
您必须使用有效的连接字符串,并且仅提供路径不是有效的连接字符串。
Data Source=C:\mydatabase.sdf;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Pass that in instead of path. 将其传递而不是路径。 Ideally this would come from the connection strings section in your config file.
理想情况下,这将来自配置文件中的“连接字符串”部分。
Here is the solution: 解决方法如下:
return Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(c => c.Is("data source=" + path)))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
.BuildSessionFactory();
Source here: http://marekblotny.blogspot.com/2009/02/fluentconfiguration-new-api-to.html 此处来源: http : //marekblotny.blogspot.com/2009/02/fluentconfiguration-new-api-to.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.