public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            // load from OLEDB catalogs
            try
            {
                DataTable schemaTable = _connection.GetSchema("Tables");

                string databaseFieldName = "TABLE_CATALOG";
                if (schemaTable.Columns[databaseFieldName] == null)
                {
                    databaseFieldName = "TABLE_CAT";
                }

                using (MetadataNamespacesFetcherFromDatatable mdf =
                           new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions))
                {
                    mdf.Datatable     = schemaTable;
                    mdf.NameFieldName = databaseFieldName;

                    mdf.LoadMetadata();
                }
            }
            catch
            {
                // loading from OLEDB catalog failed
            }

            // load default database
            string currentDatabase = Connection.Database;

            if (!string.IsNullOrEmpty(currentDatabase))
            {
                MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database);
                if (database == null)
                {
                    database      = new MetadataNamespace(databases, MetadataType.Database);
                    database.Name = currentDatabase;
                    databases.Add(database);
                }
                database.Default = true;
            }
        }
예제 #2
0
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (databases.Parent.Server == null)
            {
                if (!Connected)
                {
                    Connect();
                }

                string currentDatabase = Connection.Database;
                if (!String.IsNullOrEmpty(currentDatabase))
                {
                    MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database);
                    if (database == null)
                    {
                        database      = new MetadataNamespace(databases, MetadataType.Database);
                        database.Name = currentDatabase;
                        databases.Add(database);
                    }

                    database.Default = true;
                }
            }
        }