简体   繁体   English

如何从.Net调用Informix存储过程

[英]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. 我对Informix知之甚少。 I have a requirement to call an Informix procedure called getagentstateintervaldata 我需要调用一个名为getagentstateintervaldata的Informix过程

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 我正在使用IBM Informix ODBC驱动程序版本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. 这段代码工作正常,我在dtData数据表中返回了数据。

    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. 现在,激发Informix过程的代码。 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. 我没有办法像MS SQL的Management Studio那样连接到Informix数据库。

    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. 错误[22008] [Informix] [Informix ODBC驱动程序] [Informix]日期时间或间隔值中的字段不正确,或者在日期时间字段中指定了非法操作。

EDIT - Just to be clear here, my problem is in the Informix procedure call. 编辑 -这里要清楚,我的问题是在Informix过程调用中。 I dont understand the error(s) that are returning and I am finding very little help for the IBM Informix forums. 我不了解所返回的错误,对于IBM Informix论坛而言,我发现的帮助很小。

Thank you for any help that you all can give me. 谢谢大家提供的任何帮助。

Your problem is not related to .NET, but with your SQL. 您的问题与.NET不相关,但与您的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) 执行过程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). 1-如果在to_date()的第一个参数中指定小时,分钟,秒和分数,则必须在第二个参数(%H:%M%S%F)中使用它们。 Depending on your engine version, a "." 根据您的引擎版本,“”。 between %S and %F. 在%S和%F之间。

2- You're creating a date() from 11-01-13. 2-您要从13-01-13创建date()。 This may be ambiguous depending on your environment settings (DBDATE environment variable). 根据您的环境设置(DBDATE环境变量),这可能是不明确的。 A better way would be to use MDY() 更好的方法是使用MDY()

Hope this helps. 希望这可以帮助。 Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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