I am trying to use vbscript to connect to an iSeries DB2 database via ADO to do some very simple data retrieval, but am hitting a couple of oddities.
If I set the cursorlocation on the connection to be server side then the wscript process "disappears" after step 3 (see below). If i set the CursorLocation to be local then I get an "unspecified error " (80004005) message when trying to open the recordset.
If I copy the code into VB (and make the minor syntax changes) then everything works correctly, so it can't be access permission to the database. I've tried retrieving from a variety of files to ensure that a field name is not a protecte开发者_运维技巧d value. I've checked and ensured that the CCSID of the file on the server is 65535 (thus negating the need for a translate on the connection string). Now I'm stumped.
Anyone got any ideas?
The code is as follows:
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
This is a shot in the dark, but in my experience I generally had better results using a 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
I no longer have access to any means for testing this, sorry.
For debugging purposes, I generally preferred to use cscript
rather than wscript
so I could actually print my debugging output to the console.
精彩评论