When I use FluentNHibernate, it is not able to read connection string from web.config. I am using ASP.NET Core Web Application (.NET Framework), Fluent NHibernate 2.0.3 and NHibernate 4.0.0.4000.
The commented way works fine to access the database, while the not commented one does not work.
return Fluently.Configure()
//.Database(MySQLConfiguration.Standard.ConnectionString("Server=localhost;Port=3307; Uid=root; Pwd=usbw;Database=hellonhibernate"))
.Database(MySQLConfiguration.Standard.ConnectionString(c => c.FromConnectionStringWithKey("TRP123456")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<PersonMap>())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<SessionMap>())
.ExposeConfiguration(CreateSchema)
.BuildSessionFactory();
The web.config is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
<connectionStrings>
<add name="TRP123456" connectionString="server=localhost;port=3307;uid=root;password=admin;database=hellonhibernate;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
</configuration>
This is the error I got. Please help to see what is wrong. Thank you.
The structure of the project is as follow