2012-01-11 34 views
8

đây là tệp nlog.config của tôi. Tôi đã bật throwsException.làm tắc nghẽn bằng cách sử dụng connectionStringName để ghi nhật ký cơ sở dữ liệu

<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> 

này sẽ làm việc và sẽ chèn các bản ghi vào cơ sở dữ liệu. Tuy nhiên tôi muốn sử dụng connectionstringName và không gõ lại chuỗi kết nối. Khi tôi thay đổi connectionstring để connectionstringname như thế này ....

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

để

connectionStringName="ApplicationConnectionString" 

tôi nhận được một lỗi Mong chuỗi không trống cho 'providerInvariantName 'tham số

Trả lời

11

A dd System.Data.SqlClient để phân bổ ProviderName trong chuỗi kết nối của bạn trong web.config/app.config:

<add name="ApplicationConnectionString" 
providerName="System.Data.SqlClient" 
connectionString="server=.\SQLExpress;database=Movie;integrated security=true;"/> 
+0

Cảm ơn Nick! làm việc tuyệt vời – eiu165

+2

Bạn có thể vui lòng làm rõ nơi này đi nLog config hoặc web.config? Cảm ơn. – AlexVPerl

Các vấn đề liên quan