static public void DumpSources(string sDatabaseName, string sSourceFilename) { if (!Globals.DatabaseExists(sDatabaseName)) { return; } // If the optional filename is not included, default to the database name. if (sSourceFilename == null) { sSourceFilename = sDatabaseName + " Sources.sql"; } // If the filename does not include the path, default to the DbDir path. if (sSourceFilename.IndexOf('\\') == -1) { sSourceFilename = Globals.DbFolder + sSourceFilename; } // Open connection to database string sConnectionString = "Server=" + Globals.Server + "; Database=" + Globals.CSql(sDatabaseName) + "; User ID = sa;" + "Password=inscrutable; Connect Timeout = 2; Pooling=false;"; using (SqlConnection connection = new SqlConnection(sConnectionString)) { try { connection.Open(); } catch (Exception) { throw new Exception("Unable to open database " + sDatabaseName); } StreamWriter file = File.CreateText(sSourceFilename); DumpSource("P", "Procedures", connection, file); DumpSource("TF", "Functions", connection, file); DumpSource("TR", "Triggers", connection, file); DumpSource("V", "Views", connection, file); DumpSource("C", "Constraints", connection, file); connection.Close(); file.Flush(); file.Close(); } }
static public void DumpStructure(string sDatabaseName, string sStructureFilename) { if (!Globals.DatabaseExists(sDatabaseName)) { return; } // If the optional filename is not included, default to the database name. if (sStructureFilename == null) { sStructureFilename = sDatabaseName + " Structure.txt"; } // If the filename does not include the path, default to the DbDir path. if (sStructureFilename.IndexOf('\\') == -1) { sStructureFilename = Globals.DbFolder + sStructureFilename; } // Open connection to database string sConnectionString = "Server=" + Globals.Server + "; Database=" + Globals.CSql(sDatabaseName) + "; User ID = sa;" + "Password=inscrutable; Connect Timeout = 2; Pooling=false;"; using (SqlConnection connection = new SqlConnection(sConnectionString)) { try { connection.Open(); } catch (Exception) { throw new Exception("Unable to open database " + sDatabaseName); } StreamWriter file = File.CreateText(sStructureFilename); WriteQueryResults("Class$", "select * from Class$ order by id", connection, file); WriteQueryResults("Field$", "select * from Field$ order by id", connection, file); WriteQueryResults("ClassPar$", "select * from ClassPar$ order by src, depth", connection, file); SqlCommand command; StringCollection names = new StringCollection(); command = new SqlCommand("select name from sysobjects where type = 'u' order by name", connection); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { string s = reader.GetString(0); names.Add(s); } } finally { // Always call Close when done reading. reader.Close(); } for (int i = 0; i < names.Count; ++i) { WriteTable(names[i], connection, file); } connection.Close(); file.Flush(); file.Close(); } }