Hi im new in fluent nhibernate: I get an error when configure db conection using web.config The error is "An invalid or incomplete configuration was used.."
Web.config:
<connectionStrings>
<add name="Connection1" providerName="System.Data.SqlClient"
connectionString="Server=local;Database=aDataBase;User ID=aUser;Password=***;Trusted_Connection=False;"/>
My fluent configuration:
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("Connection1")).ShowSql() )
.Mappings(m =>m.FluentMappings.AddFromAssemblyOf<Car>())
.BuildSessionFactory();
It works if I use
.ConnectionString(@"Server=local;Database=aDataBase;User ID=aUser;Password=***;Trusted_Connection=False;"
but I want to get the connection string from Web.config (not Hard-coded).
thanks.
Try using the ConfigurationManager object to acces your connection string. Something like this should work:
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(ConfigurationManager.ConnectionStrings["Connection1"].ConnectionString).ShowSql())
.Mappings(m =>m.FluentMappings.AddFromAssemblyOf<Car>())
.BuildSessionFactory();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With