Issue with queryTask and SQL Reserved Keywords

1247
1
01-23-2011 06:09 AM
Kathleen_Crombez
Occasional Contributor III
I ran into an interesting issue using the queryTask and thought I would post my findings in hopes it can save someone else the coding heartache I just went through.

We pull data tables into SDE from the County's AS400.
One of the data tables I was performing a query on had a SQL reserved keyword used as an field name. When including the conflicting field name in the query.outFields; the query fails. This is also the case when trying to use query.outFields = ["*"];

In my example, the conflicting field name was ALL.
using query.outFields = ["ALL"]; failed
using query.outFields = ["*"]; also failed

not setting query.outFields to anything, works!

The errors produced:

Code 100005: Method failed. HRESULT = 0x8004152f : This is a FACILITY_ITF error that is specific to the interface that returned this error. See the documentation of the interface that returned this error for information about this HRESULT.

Code 10837: General GeoDatabase Error.

Code 10837: Geodatabase error: Invalid SQL syntax [Microsoft SQL Server Native Client 10.0: Incorrect syntax near the keyword 'ALL'.] [Server.DataBase.TableName].

Solution: Do not use SQL reserved keywords for field names. Now we simply rename the field when pulling the table into SDE.

Happy Debugging!
0 Kudos
1 Reply
CharlesShore
New Contributor
I got the same HRESULT error (0x8004152f) when using the following code:

It starts with this statement:
    string strQuery = "PL_PMAP == '" + txtTile.Text + "'";

which is then passed in as one of the parameters in the following statement:
     clsQuery.QueryPoly("Match Sheet", strQuery, txtTile.Text, featureSelection, 2);

and here is the recipient class:
    class clsQuery
    {
        private static IQueryFilter queryFilter = new QueryFilterClass();

        public static void QueryPoly(string dataFrame, string query, string tileNum, IFeatureSelection featureSelection, Int32 index)
        {
            queryFilter.WhereClause = query;
            featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, true);

The query is "PL_PMAP = '555'".  Everything about these statements look right -- the correct feature class is selected; it contains a string field called PL_PMAP; and, '555' is an actual value in that field.

I don't understand your statement about looking in the interface (IFeatureSelection?) to discover the cause of this error.  The limited amount of additional information about the error is also vague, although I suspect a permissions issue (???)

Thanks in advance for any light you can throw on this.
0 Kudos