Friday, January 29, 2021

Create database from schema snapshot - SQL Compare SDK

 As we explained in a previous post here, you can easily take schema snapshots using xSQL Software's SQL Compare SDK, and you can commit those schema snapshots into a source control repository to utilize for your database change control process, maintain an audit trail of database schema changes etc. In this post we will show how easy it is to create the database from a previously saved schema snapshot: 

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using xSQL.Schema.Core;
using xSQL.Schema.SqlServer;
using xSQL.SchemaCompare.SqlServer;

namespace xSQL.Sdk.SchemaCompare.Examples
{
    class DatabaseSnapshot
    {
        /// <summary>
        /// Creates the AdventureWorks database from a snapshot file.
        /// </summary>
        public static void CreateDatabaseFromSnapshot()
        {
            SqlDatabase database;
            try
            {
                //--create the database from the snapshot file
                SqlDatabase.CreateFromSnapshot(@"C:\AdventureWorks.snpx");

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

Download SQL Compare SDK now and try for yourself. 



0 comments:

Post a Comment