FluentNHibernateを使用すると、web.configから接続文字列を読み取ることができません。私はASP.NET Core Webアプリケーション(.NET Framework)、Fluent NHibernate 2.0.3およびNHibernate 4.0.0.4000を使用しています。FluentNHibernateがweb.configからconnectionStringを読み取れません
コメント付きの方法ではデータベースにアクセスできますが、コメントされていないものは機能しません。
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();
web.configファイルには、これは私が得たエラーです
<?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>
です。何が間違っているかを確認してください。ありがとうございました。
'Database(MySQLConfiguration.Standard.ConnectionString(" TRP123456 "))。データベース(MySQLConfiguration.Standard.ConnectionString(" TRP123456 ")) ))) ' –
こんにちは、お世話になりました。しかし、それは動作しないようです。私は次のコードを変更しましたが、まだNullエラーが発生します。データベース(MySQLConfiguration.Standard.ConnectionString(ConfigurationManager.ConnectionStrings ["TR P123456"])。ConnectionString)) – Ben
接続文字列を正しい 'config'ファイルに入れてください。 1つのアプリケーションしかありませんか? –