Click here to Skip to main content
13,088,846 members (64,797 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 24 Sep 2013

Enterprise Library 6 with SQLite Logging and Exception Handling, REAL!

, 25 Sep 2013
Rate this:
Please Sign up or sign in to vote.
Real and fully functional connection Database Provider and DatabaseTraceListener for SQLite!


I'm tired of watching tutorials and explanations of how to implement SQLite in Enterprise Library which did not reach anything or official articles worked, configurations, nothing about  for a single example of such could be put to work, route until reaching the version 6 it appears completely closed the support! I have worked on a fully functional example of the necessary provider to make this work!


It's true that SQLite not support stored procedures, but this is not an inconvenience, since it can create queries that simulate stored procedures, do these simulations are not slow, think there is no longer the problem of SQL Server, no connections, everything works local, direct, and SQLite can create custom functions to avoid the problem.

This provider and adapter not only creates the necessary tables to work, makes the inserts as you would the stored procedures, the created tables and relations is fully compatible with the work of the original Trace Listener.

Using the code 

Simply in your App.config  / Web.config attach the adapters, the second isn't necessary because we not use EL6, the intention is use in the future, for example with Entity Framework

      <remove invariant="System.Data.SQLite" />
      <remove invariant="System.Data.SQLite.EL6" />
      <add name="SQLite Data Provider EL6" invariant="System.Data.SQLite.EL6" description="EnterPrise Library 6 Data Provider for SQLite" type="EntLibContrib.Data.SQLite.SQLiteDatabase, EntLibContrib.Data.SQLite"  />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />      

And this in your Entlib.config

    <section name="dataConfiguration" 

        Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, 
        PublicKeyToken=31bf3856ad364e35" requirePermission="true" />

  <dataConfiguration defaultDatabase="Service_Dflt">
      <add databaseType="EntLibContrib.Data.SQLite.SQLiteDatabase, 
                EntLibContrib.Data.SQLite" name="System.Data.SQLite.EL6" />

    <add name="Service_Dflt" providerName="System.Data.SQLite.EL6" 

       connectionString="Data Source=|DataDirectory|ELSqLiteLog@|CurrentDate|.db;Version=3;" />

      <add name="Database Trace Listener" 

          type="EntLibContrib.Data.SQLite.FormattedDatabaseTraceListener, EntLibContrib.Data.SQLite"

                      FormattedDatabaseTraceListenerData, EntLibContrib.Data.SQLite"


          formatter="Text Formatter" /> 

Now you can use the "Database Trace Listener" in your <categorySources> and <specialSources> sections!

Points of Interest

Ok Ok, this is only how can you configure the Adapter and the TraceListener, but what about it, where is the magic? all the magic is in FormattedDatabaseTraceListener, you can see the code inside of the attached file.

This custom DatabaseTraceListener, is the modified version of the original of the MSSQL, the table creation are inside of code (scripts), the queries than emulates the stored procedures are too inside, because the difference of the original FormattedDatabaseTraceListener only has 2 parameter less (writeLogStoredProcName & addCategoryStoredProcName) and the calls, the result is a equal work than the original 

The SQLiteDatabase object has a little interesting present for you "|CurrentDate|" Environment Variable, can you use in the ConnectionString to make a Log file each day!


  • 1.1 Now supports Visual Studio 2010 Framework 4 with Enterprise Library 5.    
  • 1.0 Initial public release of the provider, adapter, and example.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect Sermicro
Spain Spain
My life in programming has been long, begins from the 6 years of age with Basic, I have knowledge of C++, Javascript, ASP .NET, Cisco CCNA, among others.

One of my pastimes in the programming, is cryptology and systems security

One of my recognized works is P2PFire, other smaller projects like utilities for Chats

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Southmountain24-Sep-13 6:23
memberSouthmountain24-Sep-13 6:23 
GeneralRe: My vote of 5 Pin
ModMa24-Sep-13 21:59
memberModMa24-Sep-13 21:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170813.1 | Last Updated 25 Sep 2013
Article Copyright 2013 by ModMa
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid