private ObservableCollection <NodeViewModel> GetDatabaseAssistantObjectsAsync() { ObservableCollection <NodeViewModel> databaseObjects = new ObservableCollection <NodeViewModel>(); IDbConnection connection = null; try { var assistant = DatabaseAssistant.GetDatabaseAssistant(this.connectionType); connection = assistant.CreateConnection(this.connectionString); connection.Open(); var tableContainer = new ComplexNodeViewModel("Tables"); databaseObjects.Add(tableContainer); foreach (var tableName in assistant.GetTableNames(connection).OrderBy(t => t)) { tableContainer.Children.Add(new TableNodeViewModel(this.connectionType, this.connectionString, tableName, tableContainer, SetSqlAction, true)); } var viewContainer = new ComplexNodeViewModel("Views"); databaseObjects.Add(viewContainer); foreach (var viewName in assistant.GetViewNames(connection).OrderBy(v => v)) { viewContainer.Children.Add(new TableNodeViewModel(this.connectionType, this.connectionString, viewName, viewContainer, null, false)); } if (this.connectionType != ConnectionType.Oracle) { var storedProcedureContainer = new ComplexNodeViewModel("Stored Procedures"); databaseObjects.Add(storedProcedureContainer); foreach (var spName in assistant.GetStoredProcedureNames(connection).OrderBy(sp => sp)) { storedProcedureContainer.Children.Add(new StoredProcedureNodeViewModel(assistant, connection, spName, storedProcedureContainer)); } } } catch (Exception exception) { databaseObjects.Clear(); databaseObjects.Add(new SimpleNodeViewModel(exception.Message)); } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } return(databaseObjects); }
private ObservableCollection <NodeViewModel> GetGenericDatabaseObjectsAsync() { ObservableCollection <NodeViewModel> databaseObjects = new ObservableCollection <NodeViewModel>(); ADODB.Connection connection = null; try { connection = new ADODB.ConnectionClass(); connection.Open(this.connectionString, "", "", (int)ADODB.ConnectOptionEnum.adConnectUnspecified); ADOX.Catalog catalog = new ADOX.CatalogClass(); catalog.ActiveConnection = connection; var tableContainer = new ComplexNodeViewModel("Tables"); var viewContainer = new ComplexNodeViewModel("Views"); PopulateTablesAndViews(catalog, tableContainer, viewContainer); var storedProcedureContainer = new ComplexNodeViewModel("Stored Procedures"); PopulateStoredProcedures(catalog, connection, storedProcedureContainer); databaseObjects.Add(tableContainer); databaseObjects.Add(viewContainer); databaseObjects.Add(storedProcedureContainer); } catch (Exception exception) { databaseObjects.Clear(); databaseObjects.Add(new SimpleNodeViewModel(exception.Message)); } finally { if (null != connection) { try { connection.Close(); } catch { } } } return(databaseObjects); }