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


Reads the database schema.
Syntax
'Declaration
 
Public Overloads Sub ReadSchema() 
public void ReadSchema()
public: void ReadSchema(); 
Remarks
This method reads the database schema. It should be called in order to populate the collections of database objects.
Example
The following example demonstrates how to read the schema of the database, locate a table and script it:
using xSQL.Schema.Core;
using xSQL.Schema.SqlServer;
using xSQL.SchemaCompare.SqlServer;
            
namespace xSQL.Sdk.SchemaCompare.Samples
{
    class Test
    {
        public static void ReadDatabaseSchema()
        {
            SqlServer server;
            SqlDatabase database;
            SqlTable table;
            ScriptingOptions options;
            
            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 database.SchemaOperation event in order to get progress information during the schema read
                database.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation);
                
                //--read the database schema
                database.ReadSchema();
                
                //--locate the Employee table
                table = database.SqlTables["HumanResources", "Employee"];
                if (table != null)
                {
                    //--set the script option to CREATE the object
                    options = new ScriptingOptions();
                    options.CreateScript = true;
                    options.DropScript = false;
                    options.AlterScript = false;
                    
                    //--script the table
                    Console.Write(table.GetScript(options));
                }
                
            }
            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);
        }
    }
}
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