///look in the assembly manifest resources for the script files
        ///get the ones that are SQL scripts and order them
        private ScriptStepCollection LoadScript(Version serverVersion, string database, bool dropAllConstraints, string collation, FullTextLanguage language, bool setSingleUser)
        {
            string[]             resources;
            Assembly             thisAssembly;
            ScriptStepCollection script = new ScriptStepCollection();

            thisAssembly = this.GetType().Assembly;
            resources    = thisAssembly.GetManifestResourceNames();
            int    lcid = language == null ? int.MinValue : language.Lcid;
            string dropAllConstraintsText = dropAllConstraints ? "1" : "0";
            string setSingleUserText      = setSingleUser ? "1" : "0";

            object[] formatArgs = new object[] { database, collation, dropAllConstraintsText, lcid, setSingleUserText };

            //first get a list or resources
            ArrayList resourceNames = new ArrayList();

            foreach (string resource in resources)
            {
                if (string.Compare(resource.Substring(resource.Length - 4), ".sql", true, CultureInfo.InvariantCulture) == 0)
                {
                    //we want this script...
                    //lets see if it is specific to a version of sql server
                    string versionText = resource.Substring(resource.Length - 9, 5);

                    if (versionText == ".2000")
                    {
                        if (serverVersion.Major <= 8)
                        {
                            resourceNames.Add(resource);
                        }
                    }
                    else if (versionText == ".2005")
                    {
                        if (serverVersion.Major >= 9)
                        {
                            resourceNames.Add(resource);
                        }
                    }
                    else
                    {
                        resourceNames.Add(resource);
                    }
                }
            }

            resourceNames.Sort();
            foreach (string resource in resourceNames)
            {
                script.Add(new ScriptStepResource(resource, formatArgs));
            }

            return(script);
        }
 protected override void ExecuteCommand(SqlCommand command)
 {
     script = new ScriptStepCollection();
     SqlDataReader reader = command.ExecuteReader();
     try
     {
         //this only selects the value in the first column
         while (reader.Read())
             script.Add(new ScriptStep(reader.GetString(0)));
     }
     finally
     {
         reader.Close();
     }
 }
Exemple #3
0
        protected override void ExecuteCommand(SqlCommand command)
        {
            script = new ScriptStepCollection();
            SqlDataReader reader = command.ExecuteReader();

            try
            {
                //this only selects the value in the first column
                while (reader.Read())
                {
                    script.Add(new ScriptStep(reader.GetString(0)));
                }
            }
            finally
            {
                reader.Close();
            }
        }
        ///look in the assembly manifest resources for the script files
        ///get the ones that are SQL scripts and order them
        private ScriptStepCollection LoadScript(Version serverVersion, string database, bool dropAllConstraints, string collation, FullTextLanguage language, bool setSingleUser)
        {
            string[] resources;
            Assembly thisAssembly;
            ScriptStepCollection script = new ScriptStepCollection();
            thisAssembly = this.GetType().Assembly;
            resources = thisAssembly.GetManifestResourceNames();
            int lcid = language==null ? int.MinValue : language.Lcid;
            string dropAllConstraintsText = dropAllConstraints ? "1" : "0";
			string setSingleUserText = setSingleUser ? "1" : "0";

            object[] formatArgs = new object[] { database, collation, dropAllConstraintsText, lcid, setSingleUserText };

            //first get a list or resources
            ArrayList resourceNames = new ArrayList();
            foreach (string resource in resources)
            {
                if (string.Compare(resource.Substring(resource.Length - 4), ".sql", true, CultureInfo.InvariantCulture) == 0)
                {
                    //we want this script...
                    //lets see if it is specific to a version of sql server
                    string versionText = resource.Substring(resource.Length - 9, 5);

                    if (versionText == ".2000")
                    {
                        if (serverVersion.Major <= 8)
                        {
                            resourceNames.Add(resource);
                        }
                    }
                    else if (versionText == ".2005")
                    {
                        if (serverVersion.Major >= 9)
                        {
                            resourceNames.Add(resource);
                        }
                    }
                    else
                    {
                        resourceNames.Add(resource);
                    }

                }

            }

            resourceNames.Sort();
            foreach (string resource in resourceNames)
            {
                script.Add(new ScriptStepResource(resource, formatArgs));
            }

            return script;

        }