void item_Click(object sender, EventArgs e) { try { DataSource sqlDataSource = new DataSource("MicrosoftSqlServer", "Microsoft SQL Server"); sqlDataSource.Providers.Add(DataProvider.SqlDataProvider); DataConnectionDialog dcd = new DataConnectionDialog(); dcd.DataSources.Add(sqlDataSource); dcd.SelectedDataProvider = DataProvider.SqlDataProvider; dcd.SelectedDataSource = sqlDataSource; if (DataConnectionDialog.Show(dcd) == DialogResult.OK) { string connectionString = dcd.ConnectionString; string fileName; ToolStripMenuItem item = (ToolStripMenuItem)sender; Scope scope = (Scope)item.Tag; SaveFileDialog fd = new SaveFileDialog(); fd.AutoUpgradeEnabled = true; fd.Title = "Save generated database script as"; fd.Filter = "SQL Server Compact Script (*.sqlce)|*.sqlce|SQL Server Script (*.sql)|*.sql|All Files(*.*)|"; fd.OverwritePrompt = true; fd.ValidateNames = true; if (fd.ShowDialog() == DialogResult.OK) { fileName = fd.FileName; using (IRepository repository = new ServerDBRepository(connectionString)) { var generator = new Generator(repository, fd.FileName); System.Windows.Forms.MessageBox.Show(generator.ScriptDatabaseToFile(scope)); } } } } catch (System.Data.SqlClient.SqlException sql) { Connect.ShowErrors(sql); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
void item_Click(object sender, EventArgs e) { try { var menuItem = BuildMenuItemForCommandHandler(); if (menuItem == null) { return; } var menuInfo = menuItem.CommandParameter as MenuCommandParameters; using (IRepository repository = new ServerDBRepository(menuInfo.DatabaseInfo.ConnectionString, true)) { var generator = DataConnectionHelper.CreateGenerator(repository, menuInfo.DatabaseInfo.DatabaseType); generator.GenerateTableContent(menuItem.Tag as string, false, Properties.Settings.Default.IgnoreIdentityInInsertScript); if (!Properties.Settings.Default.IgnoreIdentityInInsertScript) { generator.GenerateIdentityReset(menuItem.Tag as string, false); } ScriptFactory.Instance.CreateNewBlankScript(ScriptType.Sql); var dte = _package.GetServiceHelper(typeof(DTE)) as DTE; if (dte != null) { var doc = (TextDocument)dte.Application.ActiveDocument.Object(null); doc.EndPoint.CreateEditPoint().Insert(generator.GeneratedScript); doc.DTE.ActiveDocument.Saved = true; } DataConnectionHelper.LogUsage("TableScriptAsData"); } } catch (Exception ex) { DataConnectionHelper.SendError(ex, DatabaseType.SQLServer, false); } }
static int Main(string[] args) { if (args.Length < 2 || args.Length > 5) { PrintUsageGuide(); return(2); } else { try { string connectionString = args[0]; string outputFileLocation = args[1]; bool includeData = true; bool saveImageFiles = false; System.Collections.Generic.List <string> exclusions = new System.Collections.Generic.List <string>(); for (int i = 2; i < args.Length; i++) { if (args[i].StartsWith("schemaonly")) { includeData = false; } if (args[i].StartsWith("saveimages")) { saveImageFiles = true; } if (args[i].StartsWith("exclude:")) { ParseExclusions(exclusions, args[i]); } } using (IRepository repository = new ServerDBRepository(connectionString)) { Helper.FinalFiles = outputFileLocation; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var generator = new Generator(repository, outputFileLocation); generator.ExcludeTables(exclusions); // The execution below has to be in this sequence Console.WriteLine("Generating the tables...."); generator.GenerateTable(includeData); if (includeData) { Console.WriteLine("Generating the data...."); generator.GenerateTableContent(saveImageFiles); } Console.WriteLine("Generating the primary keys...."); generator.GeneratePrimaryKeys(); Console.WriteLine("Generating the indexes...."); generator.GenerateIndex(); Console.WriteLine("Generating the foreign keys...."); generator.GenerateForeignKeys(); Helper.WriteIntoFile(generator.GeneratedScript, outputFileLocation, generator.FileCounter); Console.WriteLine("Sent script to output file(s) : {0} in {1} ms", Helper.FinalFiles, (sw.ElapsedMilliseconds).ToString()); return(0); } } catch (System.Data.SqlClient.SqlException e) { ShowErrors(e); return(1); } catch (Exception ex) { Console.WriteLine("Error: " + ex); return(1); } } }
static int Main(string[] args) { if (args.Length < 2 || args.Length > 6) { PrintUsageGuide(); return 2; } else { try { string connectionString = args[0]; string outputFileLocation = args[1]; bool includeData = true; bool includeSchema = true; bool saveImageFiles = false; bool keepSchemaName = false; bool preserveDateAndDateTime2 = false; bool sqlite = false; System.Collections.Generic.List<string> exclusions = new System.Collections.Generic.List<string>(); for (int i = 2; i < args.Length; i++) { if (args[i].StartsWith("dataonly")) { includeData = true; includeSchema = false; } if (args[i].StartsWith("schemaonly")) { includeData = false; includeSchema = true; } if (args[i].StartsWith("saveimages")) saveImageFiles = true; if (args[i].StartsWith("keepschema")) keepSchemaName = true; if (args[i].StartsWith("preservedateanddatetime2")) preserveDateAndDateTime2 = true; if (args[i].StartsWith("exclude:")) ParseExclusions(exclusions, args[i]); if (args[i].StartsWith("sqlite")) { sqlite = true; includeSchema = true; } } using (IRepository repository = new ServerDBRepository(connectionString, keepSchemaName)) { Helper.FinalFiles = outputFileLocation; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var generator = new Generator(repository, outputFileLocation, false, preserveDateAndDateTime2, sqlite, keepSchemaName); generator.ExcludeTables(exclusions); if (sqlite) { generator.GenerateSqlitePrefix(); if (includeSchema) { Console.WriteLine("Generating the tables...."); generator.GenerateTable(false); } Console.WriteLine("Generating the data...."); generator.GenerateTableContent(false); Console.WriteLine("Generating the indexes...."); generator.GenerateIndex(); generator.GenerateSqliteSuffix(); } else { // The execution below has to be in this sequence if (includeSchema) { Console.WriteLine("Generating the tables...."); generator.GenerateTable(includeData); } if (includeData) { Console.WriteLine("Generating the data...."); generator.GenerateTableContent(saveImageFiles); } if (includeSchema) { Console.WriteLine("Generating the primary keys...."); generator.GeneratePrimaryKeys(); Console.WriteLine("Generating the indexes...."); generator.GenerateIndex(); Console.WriteLine("Generating the foreign keys...."); generator.GenerateForeignKeys(); } } Helper.WriteIntoFile(generator.GeneratedScript, outputFileLocation, generator.FileCounter, sqlite); Console.WriteLine("Sent script to output file(s) : {0} in {1} ms", Helper.FinalFiles, (sw.ElapsedMilliseconds).ToString()); return 0; } } catch (System.Data.SqlClient.SqlException e) { ShowErrors(e); return 1; } catch (Exception ex) { Console.WriteLine("Error: " + ex); return 1; } } }
static int Main(string[] args) { if (args.Length < 2 || args.Length > 6) { PrintUsageGuide(); return(2); } else { try { string connectionString = args[0]; string outputFileLocation = args[1]; bool includeData = true; bool includeSchema = true; bool saveImageFiles = false; bool keepSchemaName = false; bool preserveDateAndDateTime2 = false; bool sqlite = false; bool toExcludeTables = true; bool toIncludeTables = false; System.Collections.Generic.List <string> exclusions = new System.Collections.Generic.List <string>(); System.Collections.Generic.List <string> inclusions = new System.Collections.Generic.List <string>(); System.Collections.Generic.List <string> whereClauses = new System.Collections.Generic.List <string>(); for (int i = 2; i < args.Length; i++) { if (args[i].StartsWith("dataonly")) { includeData = true; includeSchema = false; } if (args[i].StartsWith("schemaonly")) { includeData = false; includeSchema = true; } if (args[i].StartsWith("saveimages")) { saveImageFiles = true; } if (args[i].StartsWith("keepschema")) { keepSchemaName = true; } if (args[i].StartsWith("preservedateanddatetime2")) { preserveDateAndDateTime2 = true; } if (args[i].StartsWith("exclude:")) { ParseExclusions(exclusions, args[i], whereClauses); toExcludeTables = true; toIncludeTables = false; } if (args[i].StartsWith("include:")) { ParseInclusions(inclusions, args[i], whereClauses); toIncludeTables = true; toExcludeTables = false; } if (args[i].StartsWith("sqlite")) { sqlite = true; includeSchema = true; } } using (IRepository repository = new ServerDBRepository(connectionString, keepSchemaName)) { Helper.FinalFiles = outputFileLocation; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var generator = new Generator(repository, outputFileLocation, false, preserveDateAndDateTime2, sqlite); if (toExcludeTables) { generator.ExcludeTables(exclusions); } else if (toIncludeTables) { generator.IncludeTables(inclusions, whereClauses); } if (sqlite) { generator.GenerateSqlitePrefix(); if (includeSchema) { generator.GenerateTable(false); } if (includeData) { generator.GenerateTableContent(false); } if (includeSchema) { generator.GenerateIndex(); } generator.GenerateSqliteSuffix(); } else { // The execution below has to be in this sequence if (includeSchema) { generator.GenerateTable(includeData); } if (includeData) { generator.GenerateTableContent(saveImageFiles); } if (includeSchema) { generator.GeneratePrimaryKeys(); generator.GenerateIndex(); generator.GenerateForeignKeys(); } } Helper.WriteIntoFile(generator.GeneratedScript, outputFileLocation, generator.FileCounter, sqlite); return(0); } } catch (System.Data.SqlClient.SqlException e) { ShowErrors(e); return(1); } catch (Exception ex) { return(1); } } }
public void GenerateServerDgmlFiles(object sender, ExecutedRoutedEventArgs e) { // http://www.mztools.com/articles/2007/MZ2007011.aspx var menuItem = sender as MenuItem; if (menuItem == null) { return; } var databaseInfo = menuItem.CommandParameter as DatabasesMenuCommandParameters; if (databaseInfo == null) { return; } var treeViewItem = databaseInfo.DatabasesTreeViewItem; bool originalValue = Properties.Settings.Default.KeepServerSchemaNames; try { DataSource sqlDataSource = new DataSource("MicrosoftSqlServer", "Microsoft SQL Server"); sqlDataSource.Providers.Add(DataProvider.SqlDataProvider); DataConnectionDialog dcd = new DataConnectionDialog(); dcd.DataSources.Add(sqlDataSource); dcd.SelectedDataProvider = DataProvider.SqlDataProvider; dcd.SelectedDataSource = sqlDataSource; if (DataConnectionDialog.Show(dcd) == System.Windows.Forms.DialogResult.OK) { string connectionString = dcd.ConnectionString; string fileName; PickTablesDialog ptd = new PickTablesDialog(); int totalCount = 0; using (IRepository repository = RepoHelper.CreateServerRepository(dcd.ConnectionString)) { ptd.Tables = repository.GetAllTableNamesForExclusion(); totalCount = ptd.Tables.Count; } ptd.Owner = Application.Current.MainWindow; bool?res = ptd.ShowDialog(); if (res.HasValue && res.Value == true && (ptd.Tables.Count < totalCount)) { SaveFileDialog fd = new SaveFileDialog(); fd.Title = "Save generated DGML file as"; fd.Filter = "DGML (*.dgml)|*.dgml"; fd.OverwritePrompt = true; fd.ValidateNames = true; bool?result = fd.ShowDialog(); if (result.HasValue && result.Value == true) { Properties.Settings.Default.KeepServerSchemaNames = true; fileName = fd.FileName; #if V35 using (IRepository repository = new ServerDBRepository(connectionString, Properties.Settings.Default.KeepServerSchemaNames)) #else using (IRepository repository = new ServerDBRepository4(connectionString, Properties.Settings.Default.KeepServerSchemaNames)) #endif { var generator = RepoHelper.CreateGenerator(repository, fileName); generator.GenerateSchemaGraph(connectionString, ptd.Tables); MessageBox.Show(string.Format("Saved {0}", fileName)); } } } dcd.Dispose(); } } catch (Exception ex) { MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex)); } finally { Properties.Settings.Default.KeepServerSchemaNames = originalValue; } }
void item_Click(object sender, EventArgs e) { try { DataSource sqlDataSource = new DataSource("MicrosoftSqlServer", "Microsoft SQL Server"); sqlDataSource.Providers.Add(DataProvider.SqlDataProvider); DataConnectionDialog dcd = new DataConnectionDialog(); dcd.DataSources.Add(sqlDataSource); dcd.SelectedDataProvider = DataProvider.SqlDataProvider; dcd.SelectedDataSource = sqlDataSource; if (DataConnectionDialog.Show(dcd) == DialogResult.OK) { string connectionString = dcd.ConnectionString; string fileName; ToolStripMenuItem item = (ToolStripMenuItem)sender; Scope scope = (Scope)item.Tag; SaveFileDialog fd = new SaveFileDialog(); fd.AutoUpgradeEnabled = true; fd.Title = "Save generated database script as"; fd.Filter = "SQL Server Compact Script (*.sqlce)|*.sqlce|SQL Server Script (*.sql)|*.sql|All Files(*.*)|"; fd.OverwritePrompt = true; fd.ValidateNames = true; if (fd.ShowDialog() == DialogResult.OK) { fileName = fd.FileName; using (IRepository repository = new ServerDBRepository(connectionString)) { var generator = new Generator(repository, fd.FileName); System.Windows.Forms.MessageBox.Show(generator.ScriptDatabaseToFile(scope)); } } } } catch (System.Data.SqlClient.SqlException sql) { Connect.ShowErrors(sql); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }