public static string alter(ISchemaBase target, string connectionString) { var db = target.RootParent as IDatabase; using (SqlConnection connection = new SqlConnection(connectionString)) { if (db != null && DialogResult.Yes != MessageBox.Show(String.Format("Alter {0} {1} in {2}..{3}?\n(WARNING: No automatic backup is made!)", target.ObjectType, target.Name, connection.DataSource, connection.Database), "ALTER Destination?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2)) { return("Cancelled."); } string result = string.Empty; SQLScriptList SqlDiff = target.ToSqlDiff(new List <ISchemaBase>()); string[] splitOn = { "GO" }; string[] tempList = SqlDiff.ToSQL().Split(splitOn, StringSplitOptions.RemoveEmptyEntries); List <string> scripts = new List <string>(tempList); foreach (string sql in scripts) { string script = sql; //script = script.Replace("\r", ""); //script = script.Replace("\t", ""); //script = script.Replace("\n", " "); if (target.ObjectType == Enums.ObjectType.StoredProcedure) { script = sql.Replace("CREATE PROCEDURE", "ALTER PROCEDURE"); } SqlCommand command = new SqlCommand(script, connection); try { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } catch (Exception e) { result += target.Name + ": " + e.Message + "\n\n"; connection.Close(); } } return(result); } }
public static string rebuild(ISchemaBase target, string connectionString) { SQLScriptList SqlDiff = target.ToSqlDiff(); string[] splitOn = { "GO" }; string[] tempList = SqlDiff.ToSQL().Split(splitOn, StringSplitOptions.RemoveEmptyEntries); List <string> scripts = new List <string>(tempList); string result = string.Empty; string script = scripts[0]; if (target.ObjectType == Enums.ObjectType.Table) { script = script.Replace("CREATE TABLE", "ALTER TABLE"); } MessageBox.Show(script); return(result); }
public static string alter(ISchemaBase target, string connectionString) { var db = target.RootParent as Database; if (db != null && DialogResult.Yes != MessageBox.Show(String.Format("Alter {0} {1} in {2}..{3}?\n(WARNING: No automatic backup is made!)", target.ObjectType, target.Name, db.Info.Server, db.Info.Database), "ALTER Destination?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2)) { return "Cancelled."; } string result = string.Empty; SqlConnection connection = new SqlConnection(connectionString); SQLScriptList SqlDiff = target.ToSqlDiff(); string[] splitOn = {"GO"}; string[] tempList = SqlDiff.ToSQL().Split(splitOn, StringSplitOptions.RemoveEmptyEntries); List<string> scripts = new List<string>(tempList); foreach (string sql in scripts) { string script = sql; //script = script.Replace("\r", ""); //script = script.Replace("\t", ""); //script = script.Replace("\n", " "); if (target.ObjectType == Enums.ObjectType.StoreProcedure) { script = sql.Replace("CREATE PROCEDURE", "ALTER PROCEDURE"); } SqlCommand command = new SqlCommand(script, connection); try { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } catch(Exception e) { result += target.Name + ": " + e.Message + "\n\n"; connection.Close(); } } return result; }
public static string rebuild(ISchemaBase target, string connectionString) { SQLScriptList SqlDiff = target.ToSqlDiff(); string[] splitOn = { "GO" }; string[] tempList = SqlDiff.ToSQL().Split(splitOn, StringSplitOptions.RemoveEmptyEntries); List<string> scripts = new List<string>(tempList); string result = string.Empty; string script = scripts[0]; if (target.ObjectType == Enums.ObjectType.Table) { script = script.Replace("CREATE TABLE", "ALTER TABLE"); } MessageBox.Show(script); return result; }