private void EnumerateCatalogs()
        {
            // Perform the enumeration
            DataTable dataTable = null;
            OleDbConnection connection = null;
            try
            {
                // Create a connection string without initial catalog
                OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder(Properties.ToFullString());
                builder.Remove("Initial Catalog");

                // Create a connection
                connection = new OleDbConnection(builder.ConnectionString);

                // Open the connection
                connection.Open();

                // Try to get the DBSCHEMA_CATALOGS schema rowset
                dataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Catalogs, null);
            }
            catch
            {
                dataTable = new DataTable();
                dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            // Create the object array of catalog names
            _catalogs = new object[dataTable.Rows.Count];
            for (int i = 0; i < _catalogs.Length; i++)
            {
                _catalogs[i] = dataTable.Rows[i]["CATALOG_NAME"];
            }

            // Populate the initial catalog combo box items (must occur on the UI thread)
            if (Thread.CurrentThread == _uiThread)
            {
                PopulateInitialCatalogComboBox();
            }
            else if (this.IsHandleCreated)
            {
                BeginInvoke(new ThreadStart(PopulateInitialCatalogComboBox));
            }
        }
Exemplo n.º 2
0
        public BulkCopy(OleDbConnection conn)
        {
            OleDbConnectionStringBuilder oleDbStringBuilder = new OleDbConnectionStringBuilder(conn.ConnectionString);
            oleDbStringBuilder.Remove("provider");

            IBulkCopyWrapper bulkCopyWrapper = null;
            switch (conn.Provider)
            {
                case "sqloledb":
                    bulkCopyWrapper = new SqlBulkCopyWrapper(new SqlConnection(oleDbStringBuilder.ConnectionString));
                    break;
                case "oraoledb":
                    bulkCopyWrapper = new OracleBulkCopyWrapper(new OracleConnection(oleDbStringBuilder.ConnectionString));
                    break;
                default: throw new Exception("Not Support OleDbConnection");
            }
        }