private void ReloadDataAccess() { _mDbAccess?.Dispose(); _mDbAccess = new BuilderDatabase(BuilderDatabase, BredPassword); ClearMasterSetTables(); //PMFactory.SetParameters(10000, (object)new BuildingBRTypes(), RuntimeHelpers.GetObjectValue(new object()), str, IDBAccess.DBServerType.OleDB, false); //ConnectionProvider = (IAssessmentsServiceProvider)new BREDAssessmentServiceConnectionProvider(str, PackageFileName); }
internal bool Bootstrap(string dbName) { bool flag; DatabasePath = dbName; try { _mDbAccess?.Dispose(); _mDbAccess = new BuilderDatabase(DatabasePath, BootstrapPassword); //ConnectionProvider = (IAssessmentsServiceProvider)new BREDAssessmentServiceConnectionProvider("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DatabasePath + ";Jet OLEDB:BuilderDatabase Password=erdccerl;", PackageFileName); if (TableList(DatabasePath, BootstrapPassword) == null) { throw new ApplicationException("This builderDatabase is does not appear to be a valid BUILDER RED builderDatabase.\r\n" + "Please make sure this file was downloaded from the matching version of BUILDER."); } DeleteAllLinkedTables(); var oTableNames = TableList(LookupDatabase, LookupPassword); if (oTableNames == null) { throw new ApplicationException("The critical builderDatabase named Lookup.mdb is not the most current version.\r\n" + "Please check that Builder RED has been properly installed and that you have downloaded the latest Lookup.mdb builderDatabase."); } DBLinker(LookupDatabase, oTableNames, LookupPassword); flag = true; } catch (Exception ex) { //ProjectData.SetProjectError(ex); ErrorHandler(ex, nameof(mdUtility), nameof(Bootstrap)); flag = false; //ProjectData.ClearProjectError(); } return(flag); }
public static IList <string> TableList([NotNull] IBuilderDatabase builderDatabase) { var tables = new List <string>(); try { using (var connection = builderDatabase.GetConnection()) { try { connection.Open(); // Get list of user tables var userTables = connection.GetSchema("Tables"); if (userTables != null) { foreach (DataRow row in userTables.Rows) { if (row["TABLE_Type"].ToString() == "TABLE") { tables.Add(row["TABLE_NAME"].ToString()); } } } } finally { connection.Close(); } } } catch (Exception ex) { ErrorHandler(ex, nameof(mdUtility), nameof(TableList)); } return(tables); }
public static void DeleteAllLinkedTables([NotNull] IBuilderDatabase builderDatabase) { try { #if false var displayTypes = new List <string> { //"MetaDataCollections", //"DataSourceInformation", //"DataTypes", //"Restrictions", //"ReservedWords", //"Columns", //"Indexes", //"Procedures", //"ProcedureColumns", //"ProcedureParameters", "Tables", //"Views", }; var tableNames = new List <string>(); using (var connection = builderDatabase.GetConnection()) { try { connection.Open(); // Get list of schemas var schemas = connection.GetSchema(); if (schemas != null) { for (var idx = 0; idx < schemas.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(schemas.Columns[idx].ColumnName); } Debug.WriteLine(""); foreach (DataRow row in schemas.Rows) { for (var idx = 0; idx < schemas.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(row[idx]); } Debug.WriteLine(""); } foreach (DataRow schema in schemas.Rows) { if (!displayTypes.Contains(schema[0].ToString())) { continue; } Debug.WriteLine("\r\nSchema:" + schema[0]); var rows = connection.GetSchema(schema[0].ToString()); if (rows != null) { for (var idx = 0; idx < rows.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(rows.Columns[idx].ColumnName); } Debug.WriteLine(""); foreach (DataRow row in rows.Rows) { for (var idx = 0; idx < rows.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(row[idx]); } Debug.WriteLine(""); tableNames.Add(row["TABLE_NAME"].ToString()); } } } } } finally { connection.Close(); } } #endif #if false foreach (var tableName in tableNames) { try { Debug.WriteLine("\r\nTable:" + tableName); var sysTables = builderDatabase.GetTableFromQuery("SELECT * FROM " + tableName); for (var idx = 0; idx < sysTables.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(sysTables.Columns[idx].ColumnName); } Debug.WriteLine(""); foreach (DataRow row in sysTables.Rows) { for (var idx = 0; idx < sysTables.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(row[idx]); } Debug.WriteLine(""); } } catch (Exception ex) { ErrorHandler(ex, nameof(mdUtility), nameof(DeleteAllLinkedTables)); } } #endif #if false using (var connection = builderDatabase.GetConnection()) { try { connection.Open(); var schema = connection.GetSchema(OdbcMetaDataCollectionNames.Tables); for (var idx = 0; idx < schema.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(schema.Columns[idx].ColumnName); } Debug.WriteLine(""); foreach (DataRow row in schema.Rows) { for (var idx = 0; idx < schema.Columns.Count; idx++) { Debug.WriteIf(idx > 0, ", "); Debug.Write(row[idx]); } Debug.WriteLine(""); } } finally { connection.Close(); } } #endif #if false using (var connection = builderDatabase.GetConnection()) { try { connection.Open(); var command = new OdbcCommand("SHOW TABLES", connection); var reader = command.ExecuteReader(); while (reader.Read()) { Debug.WriteLine(reader[0]); } } finally { connection.Close(); } } #endif #if false using (var connection = builderDatabase.GetConnection()) { try { var strCommand = "SELECT DISTINCTROW msysobjects.Name, msysobjects.Database, msysobjects.Connect " + "FROM msysobjects WHERE (((msysobjects.Type)=6 Or (msysobjects.Type) Like \"dsn*\")) ORDER BY msysobjects.Database;"; connection.Open(); var command = new OdbcCommand(strCommand, connection); var reader = command.ExecuteReader(); while (reader.Read()) { Debug.WriteLine(reader[0]); } } finally { connection.Close(); } } #endif } catch (Exception ex) { ErrorHandler(ex, nameof(mdUtility), nameof(DeleteAllLinkedTables)); } }