Micro Focus QTP (UFT) Forums

Full Version: connecting to oracle using vbscript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am getting the error when running the below code.
'The connection can't be used to perform this operation. It is either closed or invalid in this context'.

Please help with the below code.

Code:
'Connecting to Oracle
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set Conn_Obj = CreateObject("ADODB.Connection")
Set Rec_Obj = CreateObject("ADODB.Recordset")
Conn_Obj.Open "DRIVER= Oracle in OraClient10g_home1;SERVER = oracle_server;Data Source = FITN;UID= user1;PWD= passwd"

Rec_Obj.CursorLocation = adUseClient

Rec_Obj.Open "select ir.cusip from  market.instrument ir where ir.cusip ='20172KC78' adOpenStatic,adLockOptimistic"

While not(Rec_Obj.EOF)

Msgbox "Result " & Rec_Obj.Fields.Item("cusip")&vbCrLf

      Rec_Obj.MoveNext
      
Wend
Rec_Obj.Close
Conn_Obj.Close
Set Rec_Obj = Nothing
Set Conn_Obj = Nothing
Msgbox "It is a success"
May I know at which line you are getting this error..?
Maybe something wrong in configuration in
Code:
Conn_Obj.Open "DRIVER= Oracle in OraClient10g_home1;SERVER = oracle_server;Data Source = FITN;UID= user1;PWD= passwd"
I think you miss [,conn_obj] at last of below code

Code:
Rec_Obj.Open "select ir.cusip from market.instrument ir where ir.cusip ='20172KC78' adOpenStatic,adLockOptimistic"

Try this...!

Code:
Rec_Obj.Open "select ir.cusip from market.instrument ir where ir.cusip ='20172KC78' adOpenStatic,adLockOptimistic",conn_obj

thanks & regards,
Baba fakruddin.D
baba.fakru@gmail.com
Try this out:

Code:
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set ObjCon=createobject("adodb.connection")
Set ObjRec=createobject("adodb.recordset")
ObjCon.open "Data Source=FITN;server=oracle_server;uid=user1;pwd=passwd;db=yourDBName"
ObjRec.CursorLocation = adUseClient
ObjRec.CursorType = adOpenStatic
ObjRec.LockType = adLockOptimistic

ObjRec.Source="select ir.cusip from market.instrument ir where ir.cusip ='20172KC78' adOpenStatic,adLockOptimistic"
While not(ObjRec.EOF)
ObjRec.ActiveConnection=ObjCon
ObjRec.Open
Msgbox "Result " & ObjRec.Fields.Item("cusip")&vbCrLf
ObjRec.MoveNext
ObjRec.Close

Copy paste the whole thing.. Just u have to enter db value(delete yourDBname and pass the actual dbname)

Hope this works...

Regards,
Ritesh