2012-01-11 8 views
8

के लिए कनेक्शन स्ट्रिंगनाम यहां मेरी nlog.config फ़ाइल है। मैंने फेंकता अपवाद चालू कर दिया है।nlog डेटाबेस लॉगिंग

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

यह काम करेंगे और डेटाबेस में रिकॉर्ड दर्ज हो जाएगा। हालांकि मैं कनेक्शनस्ट्रिंगनाम का उपयोग करना चाहता हूं और कनेक्शनस्ट्रिंग को फिर से टाइप नहीं करना चाहता हूं। जब मैं connectionstring को connectionstringname इस तरह ....

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

connectionStringName="ApplicationConnectionString" 

करने के लिए बदल रहा 'providerInvariantName के लिए गैर रिक्त स्ट्रिंग की उम्मीद एक त्रुटि मिल 'पैरामीटर

उत्तर

11

ए dd System.Data.SqlClient web.config/app.config में अपने कनेक्शन स्ट्रिंग में ProviderName का श्रेय देना:

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

धन्यवाद निक! महान काम करता है – eiu165

+2

क्या आप कृपया स्पष्टीकरण दे सकते हैं कि यह nLog config या web.config कहां जाता है? धन्यवाद। – AlexVPerl

संबंधित मुद्दे