/// <summary>
        /// Creates the SQLite database from the schema read from the SQL Server.
        /// </summary>
        /// <param name="sqlitePath">The path to the generated DB file.</param>
        /// <param name="schema">The schema of the SQL server database.</param>
        /// <param name="password">The password to use for encrypting the DB or null if non is needed.</param>
        /// <param name="progressReportingHandler">A handle for progress notifications.</param>
        private static void CreateSQLiteDatabase(string sqlitePath, DatabaseSchema schema, string password, SqlConversionProgressReportingHandler progressReportingHandler, FailedViewDefinitionHandler viewFailureHandler, bool createViews)
        {
            _log.Debug("Creating SQLite database...");

            // Create the SQLite database file
            SQLiteConnection.CreateFile(sqlitePath);

            _log.Debug("SQLite file was created successfully at [" + sqlitePath + "]");

            // Connect to the newly created database
            string sqliteConnString = CreateSQLiteConnectionString(sqlitePath, password);

            // Create all tables in the new database
            Object stateLocker = new Object();
            int tableCount = 0;

            var orderedTables = schema.Tables.OrderBy(obj => obj.TableName).ToList();
            foreach (var dt in orderedTables)
            {
                using (var conn = new SQLiteConnection(sqliteConnString))
                {
                    conn.Open();
                    try
                    {
                        AddSQLiteTable(conn, dt);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("AddSQLiteTable failed", ex);
                        throw;
                    }
                    lock (stateLocker)
                    {
                        tableCount++;
                    }
                    CheckCancelled();
                    progressReportingHandler(false, true, (int)(tableCount * 50.0 / schema.Tables.Count), String.Format("Added table [{0}] to SQLite", dt.TableName));

                    _log.Debug("added schema for SQLite table [" + dt.TableName + "]");
                }
            }

            // Create all views in the new database
            int viewCount = 0;
            if (createViews)
            {
                var orderedViews = schema.Views.OrderBy(obj => obj.ViewName).ToList();
                foreach (var vs in orderedViews)
                {
                    using (var conn = new SQLiteConnection(sqliteConnString))
                    {
                        conn.Open();
                        try
                        {
                            AddSQLiteView(conn, vs, viewFailureHandler);
                        }
                        catch (Exception ex)
                        {
                            _log.Error("AddSQLiteView failed", ex);
                            throw;
                        }
                    }
                    viewCount++;
                    CheckCancelled();
                    progressReportingHandler(false, true, 50 + (int)(viewCount * 50.0 / schema.Views.Count), String.Format("Added view [{0}] to SQLite", vs.ViewName));

                    _log.Debug("added schema for SQLite view [" + vs.ViewName + "]");
                }
            }

            _log.Debug("finished adding all table/view schemas for SQLite database");
        }
 public DatabaseSchema GetDatabaseSchema()
 {
     var ds = new DatabaseSchema
     {
         Tables = this.TablesIncludeSchema,
         Views = this.Views,
     };
     return ds;   
 }