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

Posted on 2006-05-31
Last Modified: 2012-06-21
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?
Question by:FrancineTaylor
    LVL 37

    Accepted 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#
    LVL 1

    Author Comment

    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!
    LVL 1

    Author Comment

    ..oops, slight mis-typing...code *should* say:

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

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now