需要帮助在 Fluent NHibernate 中配置 SQL Server CE 连接字符串

发布于 2024-10-09 22:08:59 字数 638 浏览 2 评论 0原文

我试图使用以下代码返回会话工厂:

return Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(path))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
.BuildSessionFactory();

Path 是 .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)

我做错了什么?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟火散人牵绊 2024-10-16 22:08:59

http://connectionstrings.com/sql-server-2005-ce

我从来没有以前使用过 sdf,但我的猜测是尝试这样的事情。您必须使用有效的连接字符串,并且仅提供路径不是有效的连接字符串。

Data Source=C:\mydatabase.sdf;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

传递它而不是路径。理想情况下,这来自配置文件中的连接字符串部分。

http://connectionstrings.com/sql-server-2005-ce

I've never used an sdf before, but my guess is to try something like this. 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.

傲性难收 2024-10-16 22:08:59

这是解决方案:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文