• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1961
  • Last Modified:

Error: "more restrictions were provided" using GetSchema with ODBC connection to DSN

I want to get the schema information from a Microsoft SQL database, using an ODBC connection to the DSN for that database (this is a work constraint so it can't be changed).  The connection is made without problem, the table information comes back fine, but when I try to add a restriction it gives me an error.

Here's the code:

public void FillMySchema(OdbcConnection pConn)
    string[] restrictions = new string[4];
    restrictions[3] = "TABLE";

    DataTable dtTables = pConn.GetSchema("Tables", restrictions);

The error is: "More restrictions were provided than the requested sceme ("Tables") supports.

What I am trying to do is filter out the tables of type "SYSTEM TABLE" and leave only type "TABLE".  Am I using the syntax correctly?
  • 2
1 Solution
They actually cover this exact example in MSDN help.


you actually just want to pass "Tables" which ssays you want the tables collection .. the other restrictions are database, owner, and table name ... You are passing in 4 strings not 3.


Greg Young
MVP - C#
FrancineTaylorAuthor Commented:
Okay, I get it.  I was confused by the difference between the way OLE gets their schema and the way ODBC does it.

So if I want to get *only* tables of type "TABLE" (as opposed to "SYSTEM TABLE") in OLE I would do it this way:

   DataTable dtTables = pConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
                                                                                  new object[] { null, null, null, "TABLE" });

...but if I wanted to do the same thing with ODBC, I have to do it this way:

   DataTable dtTables = pConn.GetSchema("Tables");

   DataRow row = (DataRow)dtTables.Rows[iTable];
   string tabletype = row["TABLE_TYPE"].ToString();

   // this should filter out system files
   if (rowtype.Equals("TABLE"))
       // your code goes here

Thanks, Greg!
FrancineTaylorAuthor Commented:
..oops, slight mis-typing...code *should* say:

    if (tabletype.Equals("TABLE"))
       // your code goes here

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now