title: NLog Database Target Not Finding Table
body: <p>I am using NLog 1.0 and have the following configuration file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;nlog autoReload="true" throwExceptions="true"&gt;
  
  &lt;targets&gt;
      &lt;!--&lt;target name="console" xsi:type="ColoredConsole"
          layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" /&gt;
  
      &lt;target name="file" xsi:type="File" fileName="${basedir}/Logs/Site.log"
          layout="${date}: ${message}" /&gt;
  
      &lt;target name="eventlog" xsi:type="EventLog" source="My App" log="Application"
          layout="${date}: ${message} ${stacktrace}" /&gt;--&gt;
  
      &lt;target name="database" type="Database" connectionStringName="xxxxxxx"&gt;
  
          &lt;dbprovider&gt;mssql&lt;/dbprovider&gt;
  
          &lt;commandText&gt;
              INSERT INTO Logs (Message, Level, CreatedOn) VALUES (@message, @level, @createdOn);
          &lt;/commandText&gt;
  
          &lt;parameter name="@message" layout="${message}" /&gt;
          &lt;parameter name="@level" layout="${level}" /&gt;
          &lt;parameter name="@createdOn" layout="${date}" /&gt;
      &lt;/target&gt;
  &lt;/targets&gt;
  
  &lt;rules&gt;
      &lt;logger name="*" minlevel="Debug" appendTo="database" /&gt;
  
      &lt;!--&lt;logger name="*" minlevel="Info" writeTo="file" /&gt;
      &lt;logger name="*" minlevel="Fatal" writeTo="eventlog" /&gt;--&gt;
  &lt;/rules&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is almost a copy paste from the codeplex example supplied with nlog. In my global.ascx I have it log "Application Started!" just to test logging is working however this is where the problems begin (by the way the file target works well it's just the DB target):</p>
  
  <pre><code>System.Data.SqlClient.SqlException: Invalid object name 'Logs'.
  </code></pre>
  
  <p>Seems pretty straight forward to me, must be a typo. I check SQL Profiler and get the following:</p>
  
  <pre><code>exec sp_executesql N'
              INSERT INTO Logs (Message, Level, CreatedOn) VALUES (@message, @level, @createdOn);
          ',N'@message nvarchar(20),@level nvarchar(4),@createdOn nvarchar(19)',@message=N'Application Started!',@level=N'Info',@createdOn=N'06/25/2010 23:59:30'
  </code></pre>
  
  <p>My table create code is below:</p>
  
  <pre><code>CREATE TABLE Logs (
  Id INT IDENTITY(1, 1) NOT NULL,
  [Level] VARCHAR(5) NOT NULL,
  [Message] VARCHAR(4095) NOT NULL,
  CreatedOn DATETIME NOT NULL,
  
  CONSTRAINT PK_Logs PRIMARY KEY (Id)
  )
  </code></pre>
  
  <p>Any ideas, surely I am missing something simple?</p>
  
  <hr>
  
  <p>I managed to get this working and have a feeling my connection string is the problem. When the commandtext is changed to:</p>
  
  <pre><code>USE xxxx INSERT INTO dbo.Logs (Message, Level, CreatedOn) VALUES (@message, @level, @createdOn);
  </code></pre>
  
  <p>All works, I will try some connection strings if you know any that work with NLog let me know please!</p>