SemanticLogging-svc logging to SQLExpress Column Mapping does not match

Topics: Semantic Logging Application Block
Jun 13, 2013 at 5:09 PM
I am trying to SemanticLogging-svc to log out of process events to an SQLExpress database.

Along the way of my investigations into this block, I seemed to have picked up toversions of the SemanticLogging-svc V1.xx and V6.xx.

V1 comes with a couple of scripts for creating a Logging database which I used to build my database.

However I want to use V6 of SemanticLogging-svc but when the service attempts to commit a log event to the database it throws the error below:
Keywords : 1
Level : Critical
Message :
Opcode : Info
Task : 65433
Version : 0
Payload : [message : System.InvalidOperationException: The given ColumnMapping does not match up with any column in the source or destination.
   at System.Data.SqlClient.SqlBulkCopy.AnalyzeTargetAndCreateUpdateBulkCommand(
BulkCopySimpleResultSet internalResults)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(
BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSo
urce`1 source)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.EventListeners.S
qlDatabaseEventListener.<PublishEventsAsync>d__5.MoveNext() in c:\Builds\71\EntL
atabaseEventListener.cs:line 234]
EventName : DatabaseEventListenerWriteToDatabaseFailedInfo
Timestamp : 2013-06-13T16:22:54.6564412Z
in my SemanticLogging-svc.xml I have used the sqlDatabaseEventListener thus:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns=""
               xsi:schemaLocation=" SemanticLogging-svc.xsd">
  <!-- Optional settings for fine tuning performance and Trace Event Session identification-->

  <!-- EventSource reference definitions used by this host to listen ETW events -->
    <!-- Add event sources and EventListeners. The name attribute is from the EventSource.Name Property -->
    <!--<eventSource name="[My EventSource Name]">
        <eventListener name="[An event listener defined in <eventListeners>]" level="[The EventLevel from System.Diagnostics.Tracing.EventLevel]"/>
        [Any other event listeners]
    [... Any other EventSource]-->
    <!-- The below settings shows a simple configuration sample for the built-in non-transient fault tracing -->
    <!-- Remove this EventSource if you'd like, and add your own configuration according to the documentation -->
    <eventSource name="Microsoft.SemanticLogging">
        <eventListener name="svcRuntime" level="Warning" />

    <eventSource name="MyEventSource">
        <eventListener name="ConsoleEventListener" level="Verbose" />
        <eventListener name="DatabaseEventListener" level="Verbose" />


  <!-- Event Listener definitions used by <eventSources> referenced in <eventListener> name attribute -->
  <!-- The service identity should have security permissions to access the resource according to each event listener-->
    <sqlDatabaseEventListener name="DatabaseEventListener" tableName="Traces"
                              connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Logging;Integrated Security=True"/>
    <flatFileEventListener name="svcRuntime" fileName="SemanticLogging-svc.runtime.log" />
    <consoleEventListener name="ConsoleEventListener" formatterName="text"/>
    <!--[Add any built-in or custom EventListener definition here]-->
  <!-- Optional Formatter definitions used by <eventListeners> referenced in formatterName attribute -->
    <eventTextFormatter name="text" header="+=========================================+"/>
Are there any SQL scripts for creating the correct db schema for V6 of SemanticLogging-svc or is there any documentation on how to build the DB?

Also is there any specific information on sqlDatabaseEventListener?

I also note that the file DatabaseEventListener.sql exists in the download for V6, which I think creates stored procedures in the database for writing the logs, So I thought perhaps I am using the wrong EventListener But when I change sqlDatabaseEventListener to databaseEventListener intellisense tells me I must add requied "providerName" I can't find any documentation on this either so I tried the Provider VS uses ".NET Framework Data Provider for SQL Server" as the parameter value, but the service complains it cant find this provider. So what should the providerName be?

Sorry for being a newbie and slightly confused, but does any one know of an example which shows how to set up a database with the correct schema and an example of the correct information to provide in the service.xml?
Jun 13, 2013 at 5:23 PM
Edited Jun 13, 2013 at 5:24 PM
Here's a database in-process semantic logging example

And here's a database logging OUT-OF-PROCESS example

All you need to do is to change the connection string
Jun 14, 2013 at 12:53 PM
Thank you.

I could not see the woods for the trees yesterday.

In case others find this post of use. I re-created the Command script approach as was present in version 1, So I end up with three files:

CreateSemanticLogging_V6_Database.sql - AKA: DatabaseEventListener.sql as delivered in the nuget-package. there is no need to edit this file in any way.

the Command Script is as follows:
sqlcmd -S .\SQLEXPRESS -E -i CreateSemanticLoggingDatabase.sql
sqlcmd -S .\SQLEXPRESS -E -i CreateSemanticLogging_V6_Database.sql -d MyLogs
CreateSemanticLoggingDatabase.sql contains:
/* NOT SUPPORTED IN SQL AZURE: Both the CREATE DATABASE and DROP DATABASE statements must be in a separate file.
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'MyLogs')

 COLLATE SQL_Latin1_General_CP1_CI_AS
and finaly use DatabaseEventListener.sql as is.

This will the give you a nice package for creating a semantic logging database in SQL server (Express edition in my case) that works with version 6.

Simply run the command script under a login with appropriate rights and the database will be created.
Jul 25, 2013 at 11:30 PM
I have a couple of questions about this particular thread as I am receiving the same ColumnMapping error despite having a database which I configured using the sql scripts provided by the nuget package, i.e. CreateSemanticLoggingDatabase.sql and CreateSemanticLoggingDatabaseObjects.sql. I did alter the database creation script to use the database name 'SLAB'. My first question is whether one can use a <sqlDatabaseEventListener> or does one have to use a modified xsd that supports the <sinks> element that the example shows. It is worth noting that the default xsd that comes with the nuget package does not support any sink or sinks elements. Second, what does the //sqlDatabaseEventListener/@instanceName refer to? The documentation states: "The name of the instance originating the entries" which is unclear. I have tried using the event source, the full server name\server instance, and just the server instance name to no effect. Incidentally, here are the elements I am attempting to use:

<eventListener name="DatabaseListener" level="Verbose" />

<sqlDatabaseEventListener name="DatabaseListener" connectionString="Data Source=SERVERNAME\SERVERINSTANCE;Initial Catalog=SLAB;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD" instanceName="????" bufferingCount="1000" tableName="Traces" />

Incidentally, all of my other file loggers are working fine so I believe the problem is only with these elements. Thanks for any and all assistance.
Jul 27, 2013 at 7:50 PM
I think you maybe be using/referring to the preview release because as far as I can see sqlDatabaseEventListener does not exist in the production release. I believe that the term listener was changed to sink during development (which brings us full circle in a way). In terms of the schema the final release schema fully supports sinks as well as sqlDatabaseSink.

If you are using the CTP release then I would definitely recommend moving to the RTM release.

For example here is my config file based on the latest release:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns=""
               xsi:schemaLocation=" SemanticLogging-svc.xsd">
  <!-- Optional settings for fine tuning performance and Trace Event Session identification-->

  <!-- Sinks reference definitons used by this host to listen ETW events -->
    <sqlDatabaseSink name="sqlDB" bufferingCount="0" bufferingFlushAllTimeoutInSeconds="0"
                     connectionString="Database=SLAB;Server=(local)\SQLEXPRESS;Integrated Security=SSPI;"
                     instanceName="Demo Semantic Logging ETW Instance">
        <eventSource name="MyEventSource" level="LogAlways"/>

    <!-- The service identity should have security permissions to access the resource according to each event sink -->
    <flatFileSink name="svcRuntime" fileName="SemanticLogging-svc.runtime.log" >
        <!-- The below settings shows a simple configuration sample for the buit-in non-transient fault tracing -->
        <!-- Remove this eventSource if you'd like, and add your own configuration according to the documentation -->
        <!-- The name attribute is from the EventSource.Name Property -->
        <eventSource name="Microsoft-SemanticLogging" level="Warning"/>
      <!--[Add any built-in or custom formatter here if the sink supports text formatters]-->
      <eventTextFormatter header="----------"/>
    <!--[Add any built-in or custom sink definition here]-->


Instance name can be whatever you want it to be. Usually it would be something related to your application. The main use I can see is if you have multiple "servers" in a farm (e.g. using Windows Azure). Then you could use instanceName to identify the specific application instance that generated the log entry.

Randy Levy
Enterprise Library support engineer
Support How-to