在通过ADO连接到DB2时在VB脚本中打开记录集的问题

时间:2011-07-09 14:31:28

标签: vbscript db2 ado

我正在尝试使用vbscript通过ADO连接到iSeries DB2数据库来进行一些非常简单的数据检索,但是我遇到了一些奇怪的问题。

如果我将连接上的cursorlocation设置为服务器端,那么wscript进程在步骤3之后“消失”(见下文)。如果我将CursorLocation设置为local,那么在尝试打开记录集时会收到“未指定的错误”(80004005)消息。

如果我将代码复制到VB中(并进行次要语法更改),那么一切正常,因此无法访问数据库。我尝试从各种文件中检索,以确保字段名称不是受保护的值。我已检查并确保服务器上文件的CCSID为65535(因此无需在连接字符串上进行转换)。现在我很难过。

有人有任何想法吗?

代码如下:

msgbox "1. Started"
set currcon = getConnection()
currcon.CursorLocation = 3

msgbox "2. Connection Created"
set rcdset = getRcdSet("Select field from Library.file", currcon)
rcdset.open

msgbox "3. Recordset Open"
Moo = rcdset.fields(0)

msgbox "4. Ended"


Public Function getRcdSet(stmt, oCon)

'Basic declarations
Dim RcdSet
Set RcdSet = createobject("ADODB.Recordset")

'Create the record set
RcdSet.ActiveConnection = oCon
RcdSet.Source = stmt

'Set the return value
Set getRcdSet = RcdSet

End Function

Public Function getConnection()

'Basic connection details
Dim CurrCon
Dim ConString

'Build the connection string
ConString = "Driver={Client Access ODBC Driver (32-bit)};System=XXXXXXX;Uid="
ConString = ConString & "XXXXX"
ConString = ConString & ";Pwd="
ConString = ConString & "XXXXX"

'Create and open the connection
Set CurrCon = CreateObject("ADODB.Connection")
CurrCon.ConnectionString = ConString
CurrCon.Open

'Apply the return value
Set getConnection = CurrCon

End Function

1 个答案:

答案 0 :(得分:0)

这是一个黑暗的镜头,但根据我的经验,我通常使用Command获得更好的结果。

Dim cmd
Set cmd = createobject("ADODB.Command")
Set cmd.ActiveConnection = currcon
cmd.CommandText = "Select somecol from sometable"
cmd.prepared = true
Set rset = createobject("ADODB.Recordset")
rset.open cmd

我无法再使用任何方法对此进行测试,抱歉。

出于调试目的,我通常更喜欢使用cscript而不是wscript,所以我实际上可以将调试输出打印到控制台。