Quantcast
Channel: dbschemareader Discussions Rss Feed
Viewing all articles
Browse latest Browse all 166

New Post: OLEDB fails to read PK/FK constraints as SchemaOwner always null

$
0
0
Using the MS AdventureWorks2008 SQL DB, you can see that with a SQL Client connection all PK/FK constraints are read into the schema model correctly, but using an OLE DB connection will fail to read the constraints as the SchemaOwner will always be null and the lookup will fail.
    public List<DatabaseConstraint> Constraints(string tableName, string schemaName)
    {
        //match by table name and (nullable) schema
        return _constraints.Where(x =>
            string.Equals(x.TableName, tableName) &&
            string.Equals(x.SchemaOwner, schemaName)).ToList();
    }
This is due to ConstraintKeyMap never setting SchemaKey as the CONSTRAINT_SCHEMA is never available.

One possible workaround would be to take the TABLE_SCHEMA or PK_TABLE_SCHEMA....
    public ConstraintKeyMap(DataTable dt, ConstraintType constraintType)
    {
        -----
        if (!dt.Columns.Contains(SchemaKey))
        {
            if (!dt.Columns.Contains("TABLE_SCHEMA"))
            {
                if (!dt.Columns.Contains("PK_TABLE_SCHEMA"))
                    SchemaKey = null;
                else
                    SchemaKey = "PK_TABLE_SCHEMA";
            }
            else
                SchemaKey = "TABLE_SCHEMA";
        }
        -------------
    }
Any other suggestions?

Viewing all articles
Browse latest Browse all 166

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>