xSQL Schema Compare SDK version 9.5 for SQL Server
SaveToSnapshot(String) Method
Example 


The filename of the snapshot.
Saves the schema of the database to a snapshot file with the specified name.
Syntax
'Declaration
 
Public Overloads Sub SaveToSnapshot( _
   ByVal fileName As System.String _
) 
public void SaveToSnapshot( 
   System.string fileName
)
public: void SaveToSnapshot( 
   System.string* fileName
) 

Parameters

fileName
The filename of the snapshot.
Remarks
The snapshot is a proprietary storage file that contains the entire schema of the database. It can be used to recreate the schema of the database without the original live database.
Example
The following example shows how to create a database snapshot.
using xSQL.Schema.Core;
using xSQL.Schema.SqlServer;
using xSQL.SchemaCompare.SqlServer;
            
namespace xSQL.Sdk.SchemaCompare.Samples
{
    class Test
    {
        public static void SaveDatabaseToSnapshot()
        {
            SqlServer server;
            SqlDatabase database;
            
            try
            {
                //--create the SQL Server object, connect using Windows authentication
                server = new SqlServer(@"(local)");
                
                //--create the database object
                database = server.GetDatabase("AdventureWorks");
                
                //--attach an handler to SchemaOperation event in order to get progress information during the schema read
                database.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation);
                
                //--attach an handler to SnapshotOperation event to get snapshot feedback
                database.SnapshotOperation += new EventHandler<SnapshotOperationEventArgs>(database_SnapshotOperation);
                
                //--read the database schema
                database.ReadSchema();
                
                //--create the snapshot
                database.SaveToSnapshot(Path.Combine(@"C:\", database.GetDefaultSnapshotFilename()));
                
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }            
            
        private static void database_SchemaOperation(object sender, SchemaOperationEventArgs e)
        { 
            //--exclude verbose messages
            if (e.Message.MessageType != OperationMessageTypeEnum.Verbose)
                Console.WriteLine(e.Message.Text);
        }
        
        private static void database_SnapshotOperation(object sender, SnapshotOperationEventArgs e)
        {
            //--exclude verbose messages
            if (e.Message.MessageType != OperationMessageTypeEnum.Verbose)
                Console.WriteLine(e.Message.Text);
        }
    }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

SqlDatabase Class
SqlDatabase Members
Overload List

 

 


┬ęCopyright 2018 xSQL Software. All Rights Reserved.

Send Feedback