私は自分のプロジェクトでnlogを使用しています。私のweb.configは次のようになります:web.configファイルで接続文字列を2回使用する。別のNlog設定のため
<connectionStrings>
<add name="SQL_ConnStr" connectionString="Initial Catalog=ConfigDB;Provider=SQLOLEDB; Data Source=mysqlserver; User ID=sa; Password=sa; Persist Security Info=True;"/>
</connectionStrings>
...
<nlog>
<targets>
<target name="database" type="Database" dbProvider="sqlserver" **connectstring="Initial Catalog=ConfigDB;Provider=SQLOLEDB; Data Source=mysqlserver; User ID=sa; Password=sa"** commandText="INSERT INTO ...">
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="database"/>
</rules>
</nlog>
2つの同じ接続文字列!私の質問は、ただ1つの接続文字列を保持する方法ですか?
重要な情報を追加したいだけです。もちろん、connectionStringNameを使用する必要がありますが、接続文字列にproviderName属性を追加する必要があります(たとえば、msqlサーバーの場合はproviderName = "System.Data.SqlClient")。それがないと、NLogは "providerInvariantName 'パラメータの空でない文字列を期待しています。 –
しかし、どこにconnectionStringsセクションを置くのですか? env.ConfigureNLog( "nlog.config"); – flexxxit
@flexxxitのセクションで接続文字列名を見つけることができないというエラーが表示されます。これは別の質問です。 http://stackoverflow.com/questions/26882704/where-to-place-connection-string-in-web-configを参照してください。 –