Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nlog using the connectionStringName for database logging

here is my nlog.config file. I have turned on the throwsException.

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  throwExceptions="true">
      <targets>   
        <target type="Database" name="databaseLog"
        dbProvider="sqlserver"   connectionstring="server=.\SQLExpress;database=Movie;integrated security=true">
            <commandText>
                INSERT INTO [Log] ([Description] , [Level] ) VALUES (@Description,  @Level )
            </commandText>
            <parameter name="@Description" layout="${message}"/> 
            <parameter name="@Level" layout="${level}"/>
        </target>

      </targets>

      <rules>
         <logger name="*" minLevel="Trace"  appendTo="databaseLog"/> 
      </rules>
</nlog>

This will work and will insert records into the database. However I would like to use connectionstringName and not retype the connectionstring. When I change the connectionstring to connectionstringname like this....

connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"

to

connectionStringName="ApplicationConnectionString" 

I get an error Expecting non-empty string for 'providerInvariantName' parameter

like image 358
eiu165 Avatar asked Jan 11 '12 16:01

eiu165


1 Answers

Add System.Data.SqlClient to attribute ProviderName in your connection string in web.config/app.config:

<add name="ApplicationConnectionString" 
providerName="System.Data.SqlClient"
connectionString="server=.\SQLExpress;database=Movie;integrated security=true;"/>
like image 118
Nick Avatar answered Oct 12 '22 23:10

Nick