开发者

Need help configuring SQL Server CE connections string in Fluent NHibernate

开发者 https://www.devze.com 2023-02-01 15:34 出处:网络
I\'m trying to return a session factory using this code: return Fluently.Configure() .Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(path))

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 fu开发者_JAVA技巧ll 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号