Example #1
0
        private void Initialize(string name,
                string connectionString, string providerName)
        {
            _name = name;

            // get the provider and then get the Factory Singleton
            _factory = DbProviderFactories.GetFactory(providerName);

            //some providers, don't provide an inherited DbConnectionStringBuilder
            //so if the factory call returns null, use the default.
            _connectionStringBuilder = Factory.CreateConnectionStringBuilder() ??
                                       new DbConnectionStringBuilder(true);
            _connectionStringBuilder.ConnectionString = connectionString;
            TestConnectionStringForMicrosoftExcelOrAccess();
            using (var conn = Factory.CreateConnection())
            {
                conn.ConnectionString = ConnectionString;

                //add a state change event, if this one is called, it will
                //set up the events later, so we can keep track of how many are open
                conn.StateChange += ConnStateChange;
                conn.Open();
                _information = new DataSourceInformation(
                    conn.GetSchema(DbMetaDataCollectionNames.DataSourceInformation));
            }
        }