SQLBindParameter SQL_C_TYPE_DATE HY003 Error

I'm trying to use ODBC to send data to SQL Server from VC++. When I try to setup the parameters for sending a date to the database by calling SQLBindParameters(), I get the error HY003 "Program type out of range".

This indicates that the 4th parameter, ValueType, is not correct. But I'm hard coding it to a known valid value. Actually, I'm copies code strait from the Microsoft Help and still getting this error.

Specifically, here's the lines of code:

DATE_STRUCT dsOpenDate;
SQLINTEGER cbOpenDate = 0;
SQLBindParameter (hstmt, 3, SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TYPE_DATE, 0, 0, &dsOpenDate, 0, &cbOpenDate);

NOTE: This is from the sample in MS Help page:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2005OCT.1033/odbc/htm/odbcsqlbindparameter.htm

So, according to the error, SQL_C_TYPE_DATE is not valid. But since it's hard coded here, it must be valid. What gives

Any help would be appreciated,

Scott




Answer this question

SQLBindParameter SQL_C_TYPE_DATE HY003 Error

  • bairavinathan

    I tried this and it did not work for me.

    If I try it with DB2, Oracle or Postgres it works fine.

    It just does not work for SQL Server 2000.

    I have tried it for smalldatetime and datatime columns.

    I am using Microsoft ODBC SQL Server driver 2000.85.1117.00


  • Cameron Kloot

    Hi Scott

    Yes you are right if I use SQL_C_TYPE_TIMESTAMP etc it works. Though it means I have convert the data.

    I hope this not the same with 2005.

    Thanks for your help.


  • Vikasumit

    Hi, I'm using Excel and Access drivers, using SQL_C_TYPE_DATE and SQL_C_TYPE_TIME with sqlbindparameter function, and both drivers throw the same error "Program type out of range"!!! I've tested coding a lot of examples (including MS examples) and nothing else pass. When I asked through "SQLGetInfo(...SQL_DATETIME_LITERALS
    ...)" I received zero in the bitmask reply...so...Does they have support What's wrong I’m using XP-Pro, ODBC ver 3.52, and VC6

    A little example:

    SQLINTEGER cbTime = 0;

    ...

    SQLSetEnvAttr(m_hEnv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, 0);

    SQLBindParameter(m_hStmt, 1, SQL_PARAM_INPUT, SQL_C_TYPE_TIME, SQL_TYPE_TIME, 0, 0, &MyTime, 0, &cbTime);


  • VasuK

    By default ODBC assumes the application is an ODBC 2.x application unless you call SQLSetEnvAttr and set SQL_ATTR_ODBC_VERSION to SQL_OV_ODBC3 to enable ODBC 3.x behavior. You need to do this right after allocating the environment handle. For example

    SQLRETURN r;

    r = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);

    // This is an ODBC v3 application

    r = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);



  • Jeff Mason

    Ok, now I found in th code where I got this to work.

    I didn't. Before I generate the SQL statement, I query the database for it's available types. If SQL_TYPE_DATE is not available, then I use SQL_TYPE_TIMESTAMP instead.

    So, on DB2, Oracle, etc, the driver says SQL_TYPE_DATE is available and I use it without a problem.

    But on SQL Server, I use SQL_C_TYPE_TIMESTAMP and SQL_TYPE_TIMESTAMP instead. This is just one of those rare times where a NON-MS SQL Server implemention is nicer to the developers.

    You should try getting SQL_INTERVAL working....good luck there.

    Scott



  • chrislal

    I am getting the same issue HY003 using ODBC 3, SQLBindParameter for DATE.

    We call SQLSetEnvAttr for ODBC 3 straight after alloc env.

    It works fine if connected to another DB Vendor.

    Any ideas


  • PeterSanDiego

    Well, this problem seems more widespread than just this one instance. It seems all ODBC 3.0+ functionality fails.

    So, how do I enable ODBC 3.0 functionality When I ask the driver for the ODBC version, it says 3.52. So it obviously support 3.0 functionality.

    Specifically, I'm using SQL Server 2005 Native drivers on Windows XP Pro.

    Here's the info from the code:

    ODBCVER = 3.51
    ie: TRACE ("ODBCVER = %x\n", ODBCVER); makes "ODBCVER = 3.51" appear in the trace window.

    TCHAR szResult[30];
    SWORD nResult;
    ::SQLGetInfo (m_hdbc, SQL_ODBC_VER, szResult,
    sizeof(szResult), &nResult);
    TRACE ("SQL_ODBC_VER = %s\n", szResult); makes SQL_ODBC_VER = 03.52 appear in the trace window.

    So, I'm using a 3.0+ driver, I'm compiling with 3.0+ options. Why doesn't any 3.0+ specific functionality work Do I need to set some other option before it will work

    Scott



  • SYStems

    Well, it's been awhile since I had this problem. I don't remeber how it was resolved. But here's the code what we ended up using that worked:

    SQL_DATE_STRUCT vDate;

    nInd = sizeof (vDate);

    nRetCode = SQLBindParameter (m_hstmt, 1, SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TYPE_DATE, 10, 0, &vDate, sizeof (vDate), &nInd);

    Granted in the actual code most of the parameters are actually variables but these are the values those variables have for DATE types.

    Scott



  • SQLBindParameter SQL_C_TYPE_DATE HY003 Error