FluentNHibernate SQL Server Configuration connection string problem

This is my first attempt at Fluent NH. I save the connection string in Properties.Settings;

FnhDbString = Data Source=PC\SQLEXPRESS;Initial Catalog=FNHTest;Integrated Security=True 

If I .FromAppSetting Fluent with .FromAppSetting , I get an exception:

 ArgumentNullException Value cannot be null. Parameter name: Data Source 

If I .FromConnectionStringWithKey Fluent with .FromConnectionStringWithKey , I get an exception:

 NullReferenceException Object reference not set to an instance of an object. 

Full method:

 private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(c => c .FromAppSetting(Properties.Settings.Default.FnhDbString)) .Cache(c => c .UseQueryCache()).ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()) .BuildSessionFactory(); } 

...

So what am I doing wrong here ??

+4
source share
1 answer

Change this:

 .ConnectionString(c => c.FromAppSetting(Properties.Settings.Default.FnhDbString)) 

:

 .ConnectionString(Properties.Settings.Default.FnhDbString) 
+7
source

Source: https://habr.com/ru/post/1337283/


All Articles