Jump to content

Get the object of ADODB.Connection


Kris123
 Share

Recommended Posts

Hi,

I am creating the object for ADODB and Recordset as like this.

$oConn = ObjCreate("ADODB.Connection")
   $oRS = ObjCreate("ADODB.Recordset")

But when i try to get the objects for the above created, it is failing.

$oConn = ObjGet("", "ADODB.Connection")
   $oRS = ObjGet("", "ADODB.Recordset").

Please help me how to get the objects for already created ones.

Link to comment
Share on other sites

You already have the object when you do ObjCreate() and don't have to "Get" it again:

$oConn = ObjCreate("ADODB.Connection")
$oRS = ObjCreate("ADODB.Recordset")

MsgBox(64, "Results", "$oConn = " & VarGetType($oConn) & " (" & ObjName($oConn) & ")" & @CRLF & _
        "$oRS = " & VarGetType($oRS) & " (" & ObjName($oRS) & ")")

You could also test the result with IsObj() if you are afraid the ObjCreate() failed, see help file.

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi,

Thanks for the reply.

Here i am creating objects in one file and i want to use those objects in another file.

For example, I am creating the bellow objects in my header file Include.au3

Global $oConn = ObjCreate("ADODB.Connection")
   Global $oRS = ObjCreate("ADODB.Recordset")

In my main script, i have created a function to retrieve the database contents, so iam using in the following way.

Func _postgres_query($Query, $cloumnname, $Data)
    $oConn1 = ObjGet("", "ADODB.Connection")                              
    $oRS1 = ObjGet("ADODB.Recordset", "")                              
    $db_Settings = "DRIVER={PostgreSQL Unicode};DATABASE=test;" & _
            "SERVER=localhost;PORT=5432;Uid=postgres;" & _
            "Pwd=postgres;" & _
            "A0=0;A1=6.4;A2=0;A3=0;A4=0;A5=0;A6=;A7=100;A8=4096;A9=0;" & _
            "B0=254;B1=8190;B2=0;B3=0;B4=1;B5=1;B6=0;B7=1;B8=0;B9=1;C0=0;C1=0;C2=dd_"
    $oConn1.Open($db_Settings)
    $oRS1.Open($Query, $oConn1, 1, 3)
    $oRS1.MoveFirst
    For $iIndex = 1 To $oRS1.RecordCount
        $Value = $oRS1.Fields($cloumnname).value
        IF($Value = $Data) Then
            Return 1
        EndIf
        $oRS1.MoveNext
    Next
    Return 0
   $oConn1.Close
EndFunc  ;==>_postgres_query

when i execute, i am getting the error as

C:\Program Files\AutoIt3\Include\Include.au3 (454) : ==> Variable must be of type "Object".:

$oConn1.Open($db_Settings)

$oConn1^ ERROR

Please Help!!!!

Link to comment
Share on other sites

Do you mean two different scripts, one creates the objects and an entirely separate process is attempting to use them? I don't think that method will work.

Or do you just mean the objects are created in the Include.au3 code, and then used in the same script that file was included in? In this case, you still just need to go ahead and use the Global variable declared in the include file and already containing the appropriate object. ObjGet() is not required, but all the included files are just part of same script.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...