Exemple #1
0
        //----------------------------------------------------------------

        #region ** implementation

        private void GetSchema()
        {
            if (string.IsNullOrEmpty(_connString))
            {
                throw new ArgumentOutOfRangeException("_connString is null or empty");
            }

            // translate ODBC requests into OleDb
            string connString = OleDbConnString.TranslateConnectionString(_connString);

            // initialize this DataSet
            Reset();

            // go get the schema
            EnforceConstraints = false;
            using (var conn = new OleDbConnection(connString))
            {
                try
                {
                    conn.Open();
                    GetTables(conn);
                    GetRelations(conn);
                    GetConstraints(conn);
                    GetStoredProcedures(conn);
                }
                catch (OleDbException)
                {
                    _connString = null;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets a <see cref="OleDbSchema"/> that contains the schema for a
        /// given connection string.
        /// </summary>
        /// <param name="connString">OleDb connection string used to
        /// initialize the new <see cref="OleDbSchema"/>.</param>
        /// <returns>
        /// A new <see cref="OleDbSchema"/> containing the schema for the
        /// given <paramref name="connString"/> or null if the connection
        /// string is invalid.
        /// </returns>
        public static OleDbSchema GetSchema(string connString)
        {
            // trivial test
            connString = OleDbConnString.TranslateConnectionString(connString);
            if (string.IsNullOrEmpty(connString) ||
                connString.IndexOf("Provider=", StringComparison.OrdinalIgnoreCase) < 0)
            {
                return(null);
            }

            // connString looks OK, try getting the schema
            try
            {
                var ds = new OleDbSchema
                {
                    ConnectionString = connString
                };
                return(ds);
            }
            catch
            {
                return(null);
            }
        }