5,427,303 members and growing! (16,697 online)
Email Password   helpLost your password?
Database » Database » Utilities     Beginner License: A Public Domain dedication

Convert SQL Server DB to SQLite DB

By liron.levi

C# Utility to automatically do the conversion from SQL Server DB to SQLite DB
C# (C# 1.0, C# 2.0, C# 3.0, C#), .NET (.NET, .NET 2.0), SQL Server (SQL 2000, SQL 2005, SQL Server), DBA, Dev

Posted: 13 Jun 2008
Updated: 17 Jul 2008
Views: 9,696
Bookmarked: 44 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
11 votes for this Article.
Popularity: 4.40 Rating: 4.22 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
2 votes, 18.2%
3
4 votes, 36.4%
4
5 votes, 45.5%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

introduction

i needed to convert existing sql server databases to sqlite databases as part of 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 and 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 psuedo information_schema.table table. you can find more information about it in the internet if you want.

history

13 june 2008: initial version

08 july 2008: v 1.2 - fixed a bug that caused unique indexes to be generated as non-unique in some cases.

08 july 2008: v 1.3 - fixed a bug that caused the utility to crash sometimes when processing index information.

17 july 2008: v 1.4 - fixed a bug that caused wrong columns to become primary keys on rare occasions. Improved conversion performance.

20 july 2008: v 1.5 - added support for case-insensitive columns (COLLATE NOCASE)

22 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).

License

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

About the Author

liron.levi


My name is Liron Levi and I'm developing software for fun & profit for 15 years already. I own a small consulting business in Kiryat Tivon / ISRAEL.

My areas of expertise are:

.NET software development
Command and control software systems (C2, C4I)
GUI and usability design
Software Requirements
Software Architecture
Networking (TCP/IP)

I can be contacted directly at liron.levi@gmail.com
Occupation: Software Developer
Company: Dev-Exp consulting
Location: Israel Israel

Other popular Database articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralTurkish regional setting error and future request.memberMustafa OZCAN5:24 27 Aug '08  
GeneralRe: Turkish regional setting error and future request.memberliron.levi22hrs 6mins ago 
GeneralError with the System.Data.SQLite Assemblymemberintrospectif7:37 13 Aug '08  
GeneralRe: Error with the System.Data.SQLite Assemblymemberintrospectif9:03 13 Aug '08  
GeneralRe: Error with the System.Data.SQLite Assemblymemberliron.levi0:56 14 Aug '08  
GeneralMany thanks.memberlushdogg4:13 10 Jul '08  
GeneralRe: Many thanks.memberliron.levi11:08 10 Jul '08  
GeneralRe: Many thanks.memberlushdogg6:00 11 Jul '08  
GeneralRe: Many thanks.memberliron.levi12:57 11 Jul '08  
GeneralRe: Many thanks.memberlushdogg12:44 12 Jul '08  
GeneralAdded support for DEFAULT time columnsmemberliron.levi12:41 7 Jul '08  
GeneralRe: Added support for DEFAULT time columnsmemberMember 577574:18 8 Jul '08  
NewsAdded support for GETDATE function as DEFAULT clausememberliron.levi12:38 7 Jul '08  
General"AddSQLiteTable failed" ErrormemberMember 577574:38 7 Jul '08  
GeneralRe: "AddSQLiteTable failed" Errormemberliron.levi9:43 7 Jul '08  
GeneralError messagememberalrashidmtz8:07 3 Jul '08  
GeneralRe: Error messagememberliron.levi1:27 6 Jul '08  
GeneralRe: Error messagememberalrashidmtz12:21 7 Jul '08  
GeneralRe: Error messagememberliron.levi12:30 7 Jul '08  
GeneralNice Jobmemberdnpro3:38 13 Jun '08  
GeneralTalk About The CodemvpJohn Simmons / outlaw programmer2:06 13 Jun '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Jul 2008
Editor:
Copyright 2008 by liron.levi
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project