示例#1
0
        public static void CreateDatabaseSchema(string script)
        {
            try
            {
                DataAccessManager dam = new DataAccessManager();
                SqlConnection conn = dam.GetConnection();
                //conn.Close();
                //conn.ConnectionString = conn.ConnectionString.Replace("EBusiness", "EBusiness_New");
                //conn.Open();
                //script = script.Replace("EBusiness", "EBusiness_New");
                string[] commands = script.Split(new string[] { "GO\r\n", "\nGO\n", "Go", "Go\t" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string command in commands)
                {
                    if (!command.Contains("[EBusiness]"))
                    {
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = conn;
                        cmd.CommandText = command;
                        cmd.CommandType = CommandType.Text;
                        cmd.ExecuteNonQuery();
                    }
                }

                MessageBox.Show("Schema Created successfully.");
            }
            catch (Exception ex)
            {

                throw;
            }
        }