简体   繁体   中英

How do I call an Informix Stored Procedure from .Net

I have been racking my brain and cannot seem to find an answer to this problem. I know very little about Informix. I have a requirement to call an Informix procedure called getagentstateintervaldata

The parameters and types for the procedure are:

    p_eStartDate, DATETIME
    p_startTime, DATETIME
    p_endTime, DATETIME
    p_rgSelected, SMALLINT
    p_skillSelected, SMALLINT
    p_tmSelected, SMALLINT

I am using IBM Informix ODBC Driver Version 3.70 Visual Studio 2010, VB.Net, .Net Framework 3.5

Here is the code that I am using to fire the procedure.

First the Test Code that I am using to make sure that I can connect to the database and get data. This code works fine and I get data returned in the dtData data table.

    Dim dtData As Data.DataTable = New Data.DataTable
    Dim xQuery As String = ""

    xQuery = "Select *, (t2.EventDateTime + INTERVAL(-6) HOUR TO HOUR) as NewDatTime "
    xQuery += "From Resource as t1 "
    xQuery += "INNER JOIN AgentStateDetail AS t2 ON t2.agentID = t1.resourceID and t1.dateInactive is null  "
    xQuery += "Where t1.ResourceLoginId LIKE '51cserv%' "
    xQuery += "Order By t2.EventDateTime;"

    Dim conn As OdbcConnection = New Odbc.OdbcConnection(sysODBCConnStr)
    conn.ConnectionTimeout = 0

    Dim objCmd As New Odbc.OdbcDataAdapter(xQuery, conn)

    conn.Open()
    'Fill the dataset
    objCmd.Fill(dtData)

    'Close connection
    If conn.State = Data.ConnectionState.Open Then conn.Close()
    conn.Dispose()

Now the code that fires the Informix procedure. This is the one that keeps giving me errors. I don't have any way to connect to the Informix database like MS SQL's Management studio.

    Dim dtData As Data.DataTable = New Data.DataTable
    Dim xQuery As String = ""

    xQuery = "execute procedure getagentstateintervaldata (date('11-01-13'),to_date('12:01:00.00', '%H:%M'),to_date('11:59:59.00', '%H:%M'),1,1,1)"

    Dim conn As OdbcConnection = New Odbc.OdbcConnection(sysODBCConnStr)
    conn.ConnectionTimeout = 0

    Dim objCmd As New Odbc.OdbcDataAdapter(xQuery, conn)

    conn.Open()
    'Fill the dataset
    objCmd.Fill(dtData)

    'Close connection
    If conn.State = Data.ConnectionState.Open Then conn.Close()
    conn.Dispose()

The error that I am getting is:

ERROR [22008] [Informix][Informix ODBC Driver][Informix] A field in a datetime or interval value is incorrect or an illegal operation specified on datetime field.

EDIT - Just to be clear here, my problem is in the Informix procedure call. I dont understand the error(s) that are returning and I am finding very little help for the IBM Informix forums.

Thank you for any help that you all can give me.

Your problem is not related to .NET, but with your SQL. Basically what you're doing is:

execute procedure getagentstateintervaldata (date('11-01-13'),to_date('12:01:00.00', '%H:%M'),to_date('11:59:59.00', '%H:%M'),1,1,1)

I see two issues in this code:

1- If you specify Hours, Minutes, Seconds and Fractions in the first argument to to_date() then you have to use them in the second parameter (%H:%M%S%F). Depending on your engine version, a "." between %S and %F.

2- You're creating a date() from 11-01-13. This may be ambiguous depending on your environment settings (DBDATE environment variable). A better way would be to use MDY()

Hope this helps. Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM