Click here to Skip to main content
11,930,231 members (51,680 online)
Click here to Skip to main content
Add your own
alternative version


407 bookmarked

Convert SQL Server DB to SQLite DB

, 13 Jan 2013 Public Domain
Rate this:
Please Sign up or sign in to vote.
A C# utility to automatically do conversion from a SQL Server DB to a SQLite DB


I needed to convert the existing SQL server databases to SQLite databases as part of a DB migration program and did not find any decent free converter to do the job.

This is my attempt to solve the problem. I should warn you though that I did not have much time to test it on too many databases. In any case - the source code is very well documented and easy to understand, so if you do have a problem it should be relatively easy to fix. (Please send me the fixed source code. If you do so, I can update the software so that everybody can enjoy it.)

Using the Code

The code is split between a dataaccess project (class library) that contains the conversion code itself and a converter project (WinForms) that drives the conversion code and provides a simple UI for user interaction.

The main class that performs the conversion is the sqlservertosqlite class. It does the conversion by doing the following steps:

  1. Reading the designated SQL server schema and preparing a list of tableschema objects that contain the schema for each and every SQL server table (and associated structures like indexes).
  2. Preparing an empty sqlite database file with the schema that was read from SQL server. In this step, the code may alter few SQL-server types that are not supported directly in sqlite.
  3. Copying rows for each table from the SQL server database to the sqlite database.

Basically, that's it!

Points of Interest

In order to read the SQL server DB schema, I was mainly using the pseudo information_schema.table table. You can find more information about it on the Internet if you want.


  • 13th June, 2008: Initial version
  • 08th July, 2008: v 1.2
    • Fixed a bug that caused unique indexes to be generated as non-unique in some cases
  • 08th July, 2008: v 1.3
    • Fixed a bug that caused the utility to crash sometimes when processing index information
  • 17th July, 2008: v 1.4
    • Fixed a bug that caused wrong columns to become primary keys on rare occasions and improved conversion performance
  • 20th July, 2008: v 1.5
    • Added support for case-insensitive columns (COLLATE NOCASE)
  • 22nd July, 2008: v 1.6
    • Added support for encrypting the resulting DB file (using the built-in encryption support that exists in the SQLite .NET provider)
  • 05th October, 2008: v 1.7
    • Fixed information_schema references to use UPPER-CASE in order to resolve international character set issues (Turkish)
  • 14th December 2008: v1.8
    • Integrated support for foreign keys from the revised version made by Yogesh Jagota
    • Merged support for selective table import
  • 21st February 2009: v1.9
    • Added contribution from johnny dickson cano that allows to select using SQL server integrated security or using user name /password instead
    • Added support for converting IDENTITY columns to AUTOINCREMENT in SQLite (suggestion by Paul Shaffer)
  • 04th March 2009: v1.10
    • Fixed a bug that caused the converter to crash when encountering a datetime field in the original SQL server schema. Thanks to bmcclint for sending me the bug with the correct bugfix.
  • 23rd May 2009: v1.11
    • Added support for simulating foreign keys using triggers (contributed by Martijn Muurman)
    • Added a small bugfix so that now an 'int' type is always converted to 'integer' type in sqlite. This was needed because sqlite will autoincrement only on 'integer' column types.
  • 04th June 2009: v1.12
    • Fixed a bug in trigger generation code that caused schema generation to fail when more than a single column is referencing the same column in a foreign table
  • 20th September 2009: v1.13
    • Fixed AUTOINCREMENT bug suggested by MAEP
    • Fixed 64 bit support problem (thanks to Murry Gammash)
    • Added support for converting SQL Server views (suggested by Richard Thurgood)
  • 22nd September 2009: v1.14
    • Fixed a critical bug that caused the conversion process to fail on some SQL Server databases that used the [dbo] notation.
  • 25th September 2009: v1.15
    • Fixed a critical bug that caused the primary keys to be discarded
    • Fixed trigger generation bug
  • 4th December 2009: v1.16
    • Fixed generation code to create GUID types for SQL-Server's uniqueidentifier type (instead of nvarchar as it was until now)
    • Updated the solution to use the latest SQLite .NET provider library
  • 24th March, 2011
    • Attached compiled version of the project for anyone that doesn't have Visual Studio and still needs to use the utility
  • 1st July, 2011
    • Updated binary zip as the earlier one was missing the DLL file needed by the application
  • 15th Nov 2011: v1.17
    • Fixed a bug that caused the software to crash when encountering NULL values in some of SQL Server meta data tables
  • 19th June 2012: v1.19
    • Added support for ignoring views when creating the DB schema, Added support for blank characters inside column names.
  •  14th January 2013: v1.20
    • Fixed problem with column names
    • Added more width to the database names combo box. 


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Software Developer Arineta Cardio Imaging
Israel Israel
My name is Liron Levi and I'm developing software for fun & profit for 15 years already. I'm now working for Arineta Cardio Imaging as a software developer (the company develops a CT machine).

I can be contacted directly at or via linkedin at

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Renga Raj5-Nov-15 18:50
professionalRenga Raj5-Nov-15 18:50 
QuestionHow can I get the Live data from SQL server to SQLite? Pin
priyahp27-Oct-15 19:45
memberpriyahp27-Oct-15 19:45 
GeneralMade changes so that it can add data only without recreating the database Pin
Ricardo Pineda17-Oct-15 6:59
memberRicardo Pineda17-Oct-15 6:59 
GeneralMy vote of 5 Pin
allkf15-Sep-15 17:20
memberallkf15-Sep-15 17:20 
QuestionHow I may transfer selected records from table Pin
Member 1060244030-Jun-15 18:48
memberMember 1060244030-Jun-15 18:48 
QuestionWhy do we need conversion to SQLite when it doesn't support stored procedures instead bind it to SQL Server through Linked Server option and follow the steps mentioned in the below links? Pin
Venkat Chaitanya Kanumukula15-Jun-15 9:48
memberVenkat Chaitanya Kanumukula15-Jun-15 9:48 
GeneralMy vote of 5 Pin
Member 1164517027-Apr-15 2:40
memberMember 1164517027-Apr-15 2:40 
QuestionProblems with data types Pin
Member 1163138223-Apr-15 9:19
memberMember 1163138223-Apr-15 9:19 
Generalthanks Pin
Vahid Hossein Pour21-Apr-15 6:10
memberVahid Hossein Pour21-Apr-15 6:10 
GeneralMy vote of 5 Pin
8838813220-Apr-15 3:43
professional8838813220-Apr-15 3:43 
SuggestionAdd encoding option? Pin
Chartres2-Apr-15 4:32
memberChartres2-Apr-15 4:32 
Questionhow i will use this source code ,can you please explain Pin
Member 1131126227-Mar-15 2:21
memberMember 1131126227-Mar-15 2:21 
Questionnice tools Pin
pigbbong616-Mar-15 22:54
memberpigbbong616-Mar-15 22:54 
QuestionHierarchy Pin
Member 1144083217-Feb-15 23:35
memberMember 1144083217-Feb-15 23:35 
AnswerRe: Hierarchy Pin
liron.levi21-Feb-15 23:44
memberliron.levi21-Feb-15 23:44 
Questionvery useful one Pin
Member 1145359115-Feb-15 21:18
memberMember 1145359115-Feb-15 21:18 
QuestionExcellent job... On the other hand, I change one line to fix a bug related with Primary Key of tables with no dbo schema Pin
camilot195-Jan-15 20:32
membercamilot195-Jan-15 20:32 
QuestionView convert issues Pin
Oleksandr Kucherenko12-Dec-14 0:18
memberOleksandr Kucherenko12-Dec-14 0:18 
QuestionConcern Entity Framework Pin
Member 1105551710-Nov-14 0:29
memberMember 1105551710-Nov-14 0:29 
GeneralMy vote of 5 Pin
Maniezzo3-Nov-14 3:31
memberManiezzo3-Nov-14 3:31 
QuestionGood 5star Pin
CoffeeShop31-Oct-14 19:05
memberCoffeeShop31-Oct-14 19:05 
QuestionGOOOOOD Pin
Member 1095699316-Oct-14 21:27
memberMember 1095699316-Oct-14 21:27 
QuestionMultiple Foreign Keys Messed Up Pin
A.Russell14-Oct-14 3:42
memberA.Russell14-Oct-14 3:42 
AnswerRe: Multiple Foreign Keys Messed Up Pin
liron.levi14-Oct-14 8:13
memberliron.levi14-Oct-14 8:13 
QuestionImage Data Type conversion to BLOB Pin
Chandy@12329-Sep-14 2:56
memberChandy@12329-Sep-14 2:56 
Questionpossible to convert a sql server compact db? Pin
Rael Bauer11-Sep-14 0:53
memberRael Bauer11-Sep-14 0:53 
AnswerRe: possible to convert a sql server compact db? Pin
liron.levi11-Sep-14 3:09
memberliron.levi11-Sep-14 3:09 
QuestionConvert SQL Server DB to SQLite DB Pin
PeymanFx9-Sep-14 1:54
memberPeymanFx9-Sep-14 1:54 
GeneralNice Pin
Amol M Vaidya28-Aug-14 17:15
professionalAmol M Vaidya28-Aug-14 17:15 
QuestionTnx very much Pin
Member 454708710-Aug-14 6:25
memberMember 454708710-Aug-14 6:25 
Questionconverter is not working Pin
Member 1094752815-Jul-14 2:19
memberMember 1094752815-Jul-14 2:19 
AnswerRe: converter is not working Pin
liron.levi15-Jul-14 3:05
memberliron.levi15-Jul-14 3:05 
QuestionHaving problem in conversion from Sql express 2005 to sqlite Pin
Rahul saraswat24-Jun-14 20:26
memberRahul saraswat24-Jun-14 20:26 
GeneralNice Work Pin
wh_ghost19-Jun-14 1:50
memberwh_ghost19-Jun-14 1:50 
GeneralRe: Nice Work Pin
liron.levi19-Jun-14 2:53
memberliron.levi19-Jun-14 2:53 
QuestionConverting to .s3db format Pin
nirav savla5-Jun-14 20:40
membernirav savla5-Jun-14 20:40 
Questionconvetor error Pin
Member 1036978730-May-14 4:48
memberMember 1036978730-May-14 4:48 
AnswerRe: convetor error Pin
liron.levi31-May-14 1:15
memberliron.levi31-May-14 1:15 
GeneralRe: convetor error Pin
Member 1036978731-May-14 5:01
memberMember 1036978731-May-14 5:01 
GeneralRe: convetor error Pin
liron.levi31-May-14 6:33
memberliron.levi31-May-14 6:33 
GeneralRe: convetor error Pin
Member 1036978731-May-14 6:54
memberMember 1036978731-May-14 6:54 
GeneralRe: convetor error Pin
liron.levi31-May-14 22:42
memberliron.levi31-May-14 22:42 
GeneralRe: convetor error Pin
Member 103697871-Jun-14 1:27
memberMember 103697871-Jun-14 1:27 
GeneralThanks a lot ... Pin
cg12114-May-14 8:43
membercg12114-May-14 8:43 
QuestionCannot convert datetimeoffset. Pin
Priyakaran1013-May-14 2:34
memberPriyakaran1013-May-14 2:34 
AnswerRe: Cannot convert datetimeoffset. Pin
Member 265583229-May-14 9:35
memberMember 265583229-May-14 9:35 
QuestionThanks Pin
Thillairaja9-Apr-14 9:47
memberThillairaja9-Apr-14 9:47 
QuestionReply For Thanks Pin
sayyedtanveer25-Mar-14 23:22
groupsayyedtanveer25-Mar-14 23:22 
QuestionPerformance Pin
Hardy_Smith18-Mar-14 8:29
memberHardy_Smith18-Mar-14 8:29 
QuestionSolution to: "The process cannot access the file .." with newer System.Data.SQLite versions Pin
Member 354318414-Feb-14 2:32
memberMember 354318414-Feb-14 2:32 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 14 Jan 2013
Article Copyright 2008 by liron.levi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid