Ejemplo n.º 1
0
        public ObjectHelper.ScriptingOptions GetScriptiongOptions()
        {
            ObjectHelper.ScriptingOptions so = new ObjectHelper.ScriptingOptions();
            so.Aggregates              = chkAggregates.Checked;
            so.ApplicationRoles        = chkApplicationRoles.Checked;
            so.Assemblies              = chkAssemblies.Checked;
            so.BrokerPriorities        = chkBrokerPriorities.Checked;
            so.ClusteredIndexes        = chkClusteredIndexes.Checked;
            so.CLRTriggers             = chkCLRTriggers.Checked;
            so.CLRUserDefinedFunctions = chkCLRUserDefinedFunctions.Checked;
            so.CheckConstraints        = chkCheckConstraints.Checked;
            so.Collation             = chkCollation.Checked;
            so.Contracts             = chkContracts.Checked;
            so.DatabaseRoles         = chkDatabaseRoles.Checked;
            so.DataCompression       = chkDataCompression.Checked;
            so.Defaults              = chkDefaults.Checked;
            so.DDLTriggers           = chkDDLTriggers.Checked;
            so.DefaultConstraints    = chkDefaultConstraints.Checked;
            so.DMLTriggers           = chkDMLTriggers.Checked;
            so.ForeignKeys           = chkForeignKeys.Checked;
            so.FullTextCatalogPath   = chkFullTextCatalogPath.Checked;
            so.FullTextCatalogs      = chkFullTextCatalogs.Checked;
            so.FullTextIndexes       = chkFullTextIndexes.Checked;
            so.FullTextStopLists     = chkFullTextStopLists.Checked;
            so.MessageTypes          = chkMessageTypes.Checked;
            so.NoFileStream          = chkNoFileStream.Checked;
            so.NoIdentities          = chkNoIdentities.Checked;
            so.NonClusteredIndexes   = chkNonClusteredIndexes.Checked;
            so.PartitionFunctions    = chkPartitionFunctions.Checked;
            so.PartitionSchemes      = chkPartitionSchemes.Checked;
            so.PrimaryKeys           = chkPrimaryKeys.Checked;
            so.RemoteServiceBindings = chkRemoteServiceBindings.Checked;
            so.Routes                  = chkRoutes.Checked;
            so.Rules                   = chkRules.Checked;
            so.Schemas                 = chkSchemas.Checked;
            so.ServiceQueues           = chkServiceQueues.Checked;
            so.Services                = chkServices.Checked;
            so.SQLUserDefinedFunctions = chkSQLUserDefinedFunctions.Checked;
            so.StoredProcedures        = chkStoredProcedures.Checked;
            so.Synonyms                = chkSynonyms.Checked;
            so.Tables                  = chkTables.Checked;
            so.UniqueConstraints       = chkUniqueConstraints.Checked;
            so.UserDefinedDataTypes    = chkUserDefinedDataTypes.Checked;
            so.UserDefinedTableTypes   = chkUserDefinedTableTypes.Checked;
            so.UserDefinedTypes        = chkUserDefinedTypes.Checked;
            so.Users                   = chkUsers.Checked;
            so.Views                   = chkViews.Checked;
            so.XMLSchemaCollections    = chkXMLSchemaCollections.Checked;

            return(so);
        }
Ejemplo n.º 2
0
        public ObjectFetch(Server srv1, string db1, string uId1, string pwd1, Server srv2, string db2, string uId2, string pwd2, ObjectHelper.ScriptingOptions so)
        {
            server1   = srv1;
            server2   = srv2;
            database1 = db1;
            database2 = db2;
            userId1   = uId1;
            userId2   = uId2;
            password1 = pwd1;
            password2 = pwd2;
            scriptOpt = so;



            InitializeComponent();
        }
Ejemplo n.º 3
0
        private void Script(object[] scriptParams)
        {
            Server srv = (Server)scriptParams[0];

            string[] lv = new String[2];

            int srvVersion = srv.Version.Major;

            this.Invoke(new MethodInvoker(delegate
            {
                lv[0] = "Connecting to Database: " + scriptParams[1].ToString();
                lv[1] = "";
                lwProgress.Items.Add(new ListViewItem(lv, 0));
            }));


            Database db = srv.Databases[scriptParams[1].ToString()];

            Hashtable hsObject = (Hashtable)scriptParams[3];

            this.Invoke(new MethodInvoker(delegate
            {
                ListViewItem lvi     = lwProgress.Items[lwProgress.Items.Count - 1];
                lvi.SubItems[1].Text = "OK";
            }));

            string connectionString = srv.ConnectionContext.ConnectionString + "; Initial Catalog='" + scriptParams[1].ToString() + "'";

            ObjectDB objectDB = new ObjectDB(connectionString);


            this.Invoke(new MethodInvoker(delegate
            {
                lv[0] = "Fetching Objects: ";
                lv[1] = "";
                lwProgress.Items.Add(new ListViewItem(lv, 0));
            }));

            ObjectHelper.ScriptingOptions so = (ObjectHelper.ScriptingOptions)scriptParams[2];

            so.ServerMajorVersion   = srv.VersionMajor;
            objectDB.ObjectFetched += new ObjectFetchedEventHandler(ObjectFetched);
            objectDB.FetchObjects(so);

            this.Invoke(new MethodInvoker(delegate
            {
                ListViewItem lvi     = lwProgress.Items[lwProgress.Items.Count - 1];
                lvi.SubItems[1].Text = "OK";
            }));

            ScriptedObject scriptedObj;

            int objectCount = 0;

            objectCount = objectCount + objectDB.Aggregates.Count;
            objectCount = objectCount + objectDB.Assemblies.Count;
            objectCount = objectCount + objectDB.ApplicationRoles.Count;
            objectCount = objectCount + objectDB.BrokerPriorities.Count;
            objectCount = objectCount + objectDB.CLRTriggers.Count;
            objectCount = objectCount + objectDB.CLRUserDefinedFunctions.Count;
            objectCount = objectCount + objectDB.Contracts.Count;
            objectCount = objectCount + objectDB.DatabaseRoles.Count;
            objectCount = objectCount + objectDB.DDLTriggers.Count;
            objectCount = objectCount + objectDB.Defaults.Count;
            objectCount = objectCount + objectDB.DMLTriggers.Count;
            objectCount = objectCount + objectDB.FullTextCatalogs.Count;
            objectCount = objectCount + objectDB.FullTextStopLists.Count;
            objectCount = objectCount + objectDB.Indexes.Count;
            objectCount = objectCount + objectDB.MessageTypes.Count;
            objectCount = objectCount + objectDB.PartitionFunctions.Count;
            objectCount = objectCount + objectDB.PartitionSchemes.Count;
            objectCount = objectCount + objectDB.RemoteServiceBindings.Count;
            objectCount = objectCount + objectDB.Routes.Count;
            objectCount = objectCount + objectDB.Rules.Count;
            objectCount = objectCount + objectDB.Schemas.Count;
            objectCount = objectCount + objectDB.ServiceQueues.Count;
            objectCount = objectCount + objectDB.Services.Count;
            objectCount = objectCount + objectDB.SQLUserDefinedFunctions.Count;
            objectCount = objectCount + objectDB.StoredProcedures.Count;
            objectCount = objectCount + objectDB.Synonyms.Count;
            objectCount = objectCount + objectDB.Tables.Count;
            objectCount = objectCount + objectDB.UserDefinedDataTypes.Count;
            objectCount = objectCount + objectDB.UserDefinedTableTypes.Count;
            objectCount = objectCount + objectDB.UserDefinedTypes.Count;
            objectCount = objectCount + objectDB.Users.Count;
            objectCount = objectCount + objectDB.Views.Count;
            objectCount = objectCount + objectDB.XMLSchemaCollections.Count;



            foreach (Aggregate obj in objectDB.Aggregates)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "Aggregate";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }


            foreach (Assembly obj in objectDB.Assemblies)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "Assembly";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }



            foreach (ObjectHelper.DBObjectType.BrokerPriority obj in objectDB.BrokerPriorities)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "BrokerPriority";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (Principal obj in objectDB.ApplicationRoles)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "ApplicationRole";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (CLRTrigger obj in objectDB.CLRTriggers)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                if (obj.IsDatabaseTrigger)
                {
                    scriptedObj.Type = "CLRDDLTrigger";
                }
                else
                {
                    scriptedObj.Type = "CLRDMLTrigger";
                }
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (CLRUserDefinedFunction obj in objectDB.CLRUserDefinedFunctions)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                if (obj.IsTableValued)
                {
                    scriptedObj.Type = "CLRUserDefinedTableFunction";
                }
                else
                {
                    scriptedObj.Type = "CLRUserDefinedFunction";
                }
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (Contract obj in objectDB.Contracts)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "SERVICECONTRACT";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (Principal obj in objectDB.DatabaseRoles)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "DatabaseRole";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Trigger obj in objectDB.DDLTriggers)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "SQLDDLTrigger";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Default obj in objectDB.Defaults)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "Default";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Trigger obj in objectDB.DMLTriggers)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "SQLDMLTrigger";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.FullTextCatalog obj in objectDB.FullTextCatalogs)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Type             = "FullTextCatalog";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.FullTextStopList obj in objectDB.FullTextStopLists)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "FullTextStopList";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Index obj in objectDB.Indexes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Type             = "Index";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.MessageType obj in objectDB.MessageTypes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "MessageType";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.PartitionFunction obj in objectDB.PartitionFunctions)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "PartitionFunction";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.PartitionScheme obj in objectDB.PartitionSchemes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "PartitionScheme";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.RemoteServiceBinding obj in objectDB.RemoteServiceBindings)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "REMOTESERVICEBINDING";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Route obj in objectDB.Routes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "SERVICEROUTE";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Rule obj in objectDB.Rules)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "Rule";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Schema obj in objectDB.Schemas)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "Schema";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.ServiceQueue obj in objectDB.ServiceQueues)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "SERVICEQUEUE";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Service obj in objectDB.Services)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Type             = "Service";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.SQLUserDefinedFunction obj in objectDB.SQLUserDefinedFunctions)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                if (obj.IsTableValued)
                {
                    scriptedObj.Type = "SQLUserDefinedTableFunction";
                }
                else
                {
                    scriptedObj.Type = "SQLUserDefinedFunction";
                }
                //scriptedObj.Type = "SQLUserDefinedFunction";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.StoredProcedure obj in objectDB.StoredProcedures)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "StoredProcedure";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Synonym obj in objectDB.Synonyms)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "Synonym";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Table obj in objectDB.Tables)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "Table";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.UserDefinedDataType obj in objectDB.UserDefinedDataTypes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "UserDefinedDataType";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.UserDefinedTableType obj in objectDB.UserDefinedTableTypes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "UserDefinedTableType";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.UserDefinedType obj in objectDB.UserDefinedTypes)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "UserDefinedType";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.Principal obj in objectDB.Users)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "User";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.View obj in objectDB.Views)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script(so);
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "View";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }

            foreach (ObjectHelper.DBObjectType.XMLSchemaCollection obj in objectDB.XMLSchemaCollections)
            {
                scriptedObj                  = new ScriptedObject();
                scriptedObj.Name             = obj.Name;
                scriptedObj.ObjectDefinition = obj.Script();
                scriptedObj.Schema           = obj.Schema;
                scriptedObj.Type             = "XMLSCHEMACOLLECTION";
                hsObject.Add(Guid.NewGuid().ToString(), scriptedObj);
            }
        }
Ejemplo n.º 4
0
        public string GenerateScript(ScriptingOptions so)
        {
            StringBuilder sql = new StringBuilder();

            int resultSetCount = 0;

            if (so.PartitionFunctions)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.PartitionFunctions.sql"));
                sql.AppendLine();
                ResultSets.Add("PartitionFunctionCollection", resultSetCount++);
                ResultSets.Add("PartitionFunctionRangeValuesCollection", resultSetCount++);
            }
            if (so.Tables)
            {
                sql.Append("SELECT COUNT(*) FROM sys.tables;");
                sql.AppendLine();
                ResultSets.Add("TableCount", resultSetCount++);
                sql.Append(GetResourceScript("ObjectHelper.SQL.Tables_" + so.ServerMajorVersion.ToString() + ".sql"));
                sql.AppendLine();
                ResultSets.Add("TableCollection", resultSetCount++);

                if (so.DataCompression)
                {
                    if (so.ServerMajorVersion >= 10)
                    {
                        sql.Append(GetResourceScript("ObjectHelper.SQL.TableDataCompression_" + so.ServerMajorVersion.ToString() + ".sql"));
                        sql.AppendLine();
                        ResultSets.Add("TableDataCompressionCollection", resultSetCount++);
                    }
                    else
                    {
                        so.DataCompression = false;
                    }
                }
                if (so.DefaultConstraints)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.DefaultConstraints.sql"));
                    sql.AppendLine();
                    ResultSets.Add("DefaultConstraintCollection", resultSetCount++);
                }
                if (so.CheckConstraints)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.CheckConstraints.sql"));
                    sql.AppendLine();
                    ResultSets.Add("CheckConstraintCollection", resultSetCount++);
                }
                if (so.ForeignKeys)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.ForeignKeys.sql"));
                    sql.AppendLine();
                    ResultSets.Add("ForeignKeyCollection", resultSetCount++);
                    ResultSets.Add("ForeignKeyColumnCollection", resultSetCount++);
                }
                if (so.FullTextIndexes)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.FullTextIndexes_" + so.ServerMajorVersion + ".sql"));
                    sql.AppendLine();
                    ResultSets.Add("FullTextIndexCollection", resultSetCount++);
                    ResultSets.Add("FullTextIndexColumnCollection", resultSetCount++);
                }
                sql.Append(GetResourceScript("ObjectHelper.SQL.Columns_" + so.ServerMajorVersion.ToString() + ".sql"));
                sql.AppendLine();
                ResultSets.Add("ColumnCollection", resultSetCount++);
            }
            if (so.Contracts)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Contracts.sql"));
                sql.AppendLine();
                ResultSets.Add("ContractCollection", resultSetCount++);
                ResultSets.Add("ContractMessageTypeCollection", resultSetCount++);
            }
            if (so.MessageTypes)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.MessageTypes.sql"));
                sql.AppendLine();
                ResultSets.Add("MessageTypeCollection", resultSetCount++);
            }
            if (so.XMLSchemaCollections)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.XMLSchemaCollections.sql"));
                sql.AppendLine();
                ResultSets.Add("XMLSchemaCollection", resultSetCount++);
            }
            if (so.UniqueConstraints || so.PrimaryKeys || so.ClusteredIndexes || so.NonClusteredIndexes)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Indexes_" + so.ServerMajorVersion + ".sql"));
                sql.AppendLine();
                ResultSets.Add("IndexCollection", resultSetCount++);
                sql.Append(GetResourceScript("ObjectHelper.SQL.IndexColumns.sql"));
                sql.AppendLine();
                ResultSets.Add("IndexColumnCollection", resultSetCount++);
            }
            if (so.DMLTriggers || so.DDLTriggers)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Triggers_" + so.ServerMajorVersion + ".sql"));
                sql.AppendLine();
                ResultSets.Add("TriggerCollection", resultSetCount++);
            }
            if (so.CLRTriggers)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.CLRTriggers_" + so.ServerMajorVersion + ".sql"));
                sql.AppendLine();
                ResultSets.Add("CLRTriggerCollection", resultSetCount++);
                ResultSets.Add("CLRTriggerEventCollection", resultSetCount++);
            }
            if (so.StoredProcedures)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.StoredProcedures.sql"));
                sql.AppendLine();
                ResultSets.Add("SPCollection", resultSetCount++);
            }
            if (so.Aggregates || so.StoredProcedures || so.SQLUserDefinedFunctions || so.CLRUserDefinedFunctions)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Parameters_" + so.ServerMajorVersion + ".sql"));
                sql.AppendLine();
                ResultSets.Add("ParameterCollection", resultSetCount++);
            }
            if (so.Aggregates)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Aggregates.sql"));
                sql.AppendLine();
                ResultSets.Add("AggregateCollection", resultSetCount++);
            }
            if (so.Views)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Views.sql"));
                sql.AppendLine();
                ResultSets.Add("ViewCollection", resultSetCount++);
            }

            if (so.ApplicationRoles || so.DatabaseRoles || so.Users) //DOROBIT DALSIE
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Principals.sql"));
                sql.AppendLine();
                ResultSets.Add("PrincipalCollection", resultSetCount++);
            }

            if (so.Assemblies)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Assemblies_" + so.ServerMajorVersion.ToString() + ".sql"));
                sql.AppendLine();
                ResultSets.Add("AssemblyCollection", resultSetCount++);
            }

            if (so.Defaults)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Defaults.sql"));
                sql.AppendLine();
                ResultSets.Add("DefaultCollection", resultSetCount++);
            }

            if (so.Synonyms)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Synonyms.sql"));
                sql.AppendLine();
                ResultSets.Add("SynonymCollection", resultSetCount++);
            }

            if (so.ServiceQueues)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.ServiceQueues.sql"));
                sql.AppendLine();
                ResultSets.Add("QueueCollection", resultSetCount++);
            }
            if (so.FullTextCatalogs)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.FullTextCatalogs.sql"));
                sql.AppendLine();
                ResultSets.Add("FullTextCatalogCollection", resultSetCount++);
            }

            if (so.FullTextStopLists)
            {
                if (so.ServerMajorVersion >= 10)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.FullTextStopLists.sql"));
                    sql.AppendLine();
                    ResultSets.Add("FullTextStopListCollection", resultSetCount++);
                    ResultSets.Add("FullTextStopWordCollection", resultSetCount++);
                }
                else
                {
                    so.FullTextStopLists = false;
                }
            }
            if (so.Services)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Services.sql"));
                sql.AppendLine();
                ResultSets.Add("ServiceCollection", resultSetCount++);
                ResultSets.Add("ServiceContractCollection", resultSetCount++);
            }
            if (so.BrokerPriorities)
            {
                if (so.ServerMajorVersion >= 10)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.BrokerPriorities.sql"));
                    sql.AppendLine();
                    ResultSets.Add("BrokerPriorityCollection", resultSetCount++);
                }
                else
                {
                    so.BrokerPriorities = false;
                }
            }
            if (so.PartitionSchemes)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.PartitionSchemes.sql"));
                sql.AppendLine();
                ResultSets.Add("PartitionSchemeCollection", resultSetCount++);
                ResultSets.Add("PartitionSchemeFileGroupCollection", resultSetCount++);
            }
            if (so.RemoteServiceBindings)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.RemoteServiceBindings.sql"));
                sql.AppendLine();
                ResultSets.Add("RemoteServiceBindingCollection", resultSetCount++);
            }
            if (so.Rules)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Rules.sql"));
                sql.AppendLine();
                ResultSets.Add("RuleCollection", resultSetCount++);
            }
            if (so.Routes)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Routes.sql"));
                sql.AppendLine();
                ResultSets.Add("RouteCollection", resultSetCount++);
            }
            if (so.Schemas)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.Schemas.sql"));
                sql.AppendLine();
                ResultSets.Add("SchemaCollection", resultSetCount++);
            }
            if (so.SQLUserDefinedFunctions)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.SQLUserDefinedFunctions.sql"));
                sql.AppendLine();
                ResultSets.Add("UserDefinedFunctionCollection", resultSetCount++);
            }
            if (so.CLRUserDefinedFunctions)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.CLRUserDefinedFunctions_" + so.ServerMajorVersion + ".sql"));
                sql.AppendLine();
                ResultSets.Add("CLRUserDefinedFunctionCollection", resultSetCount++);
                ResultSets.Add("CLRUserDefinedFunctionColumnCollection", resultSetCount++);
            }
            if (so.UserDefinedDataTypes)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.UserDefinedDataTypes_" + so.ServerMajorVersion + ".sql"));
                sql.AppendLine();
                ResultSets.Add("UserDefinedDataTypeCollection", resultSetCount++);
            }
            if (so.UserDefinedTypes)
            {
                sql.Append(GetResourceScript("ObjectHelper.SQL.UserDefinedTypes.sql"));
                sql.AppendLine();
                ResultSets.Add("UserDefinedTypeCollection", resultSetCount++);
            }
            if (so.UserDefinedTableTypes)
            {
                if (so.ServerMajorVersion >= 10)
                {
                    sql.Append(GetResourceScript("ObjectHelper.SQL.UserDefinedTableTypes.sql"));
                    sql.AppendLine();
                    ResultSets.Add("UserDefinedTableTypeCollection", resultSetCount++);
                    ResultSets.Add("UserDefinedTableTypeColumnCollection", resultSetCount++);
                    ResultSets.Add("UserDefinedTableTypeIndexCollection", resultSetCount++);
                    ResultSets.Add("UserDefinedTableTypeIndexColumnCollection", resultSetCount++);
                    ResultSets.Add("UserDefinedTableTypeCheckConstraintCollection", resultSetCount++);
                }
                else
                {
                    so.UserDefinedTableTypes = false;
                }
            }

            return(sql.ToString());
        }