Page 1 of 1

adodb one or more connection

PostPosted: Fri Feb 17, 2023 4:17 pm
by damianodec
Hi,
Can I to have two adodb connections at the same time on different databases?

I have two servers and I'd like to open one connection tu DB2 and another to SQL Server.

thank you

Damiano.

Re: adodb one or more connection

PostPosted: Sat Feb 18, 2023 11:27 am
by Enrico Maria Giordano
Yes, what's the problem?

Re: adodb one or more connection

PostPosted: Sat Feb 18, 2023 6:54 pm
by Armando
Damiano:

Why not?

Regards

Re: adodb one or more connection

PostPosted: Wed Feb 22, 2023 7:52 am
by damianodec
I open the first connection (DB2):
pgm1.prg
Code: Select all  Expand view
Connessione := "Provider=IBMDA400; Data Source=192.168.1.1; User Id=userid; Password=password; Default Collection=Library;"
oCn := FW_OpenAdoConnection( Connessione, .t.)
 

DB2 connection remains open for the duration of the program.

I open the second connection (SQl Server):
pgm2.prg
Code: Select all  Expand view
cConnSrv := "Provider=SQLOLEDB;server=192.168.1.2\SQLSERVER;database=MYDB;uid=sa;pwd=sa"
oCnSrv := FW_OpenAdoConnection( cConnSrv, .t.)
...
...
tuple := "SELECT A, B FROM SQLTABLE "
oDbo := FW_OpenRecordSet( oCnSrv, tuple, 1 )   
xbrowse(oDbo)
oDbo:Close()
oCnSrv:Close()
Return NIL
 


then reopen the pgm2.prg (SQL SERVER) and to istruction
Code: Select all  Expand view
oDbo := FW_OpenRecordSet( oCnSrv, tuple, 1 )

I Get that error: IBMDA400 is it's already open (the first connection).

in adofuncs.pgm if I comment out the lines 91-94 and 100-103 the pgm works without errors
Code: Select all  Expand view

91   if If( Empty( cSpec ), cConnStr == scStr1 .or. cConnStr == scStr2, cSpec == scSpec )
92     soCn_Check()
93     return soCn
94   endif
95
96  if ! Empty( cSpec )
97      cConnStr    := FW_AdoConnectionString( cConnStr, @nDB )
98   endif
99
100   if ( ! Empty( cSpec ) .and. cSpec == scSpec ) .or. cConnStr == scStr1 .or. cConnStr == scStr2
101     soCn_Check()
102     return soCn
103  endif
 


Why ?

Re: adodb one or more connection

PostPosted: Wed Feb 22, 2023 4:09 pm
by Armando
Damiano:

Try with ReOpen

Code: Select all  Expand view

FW_ReOpenRecordSet(oDbo,oCnSrv, tuple, 1 )
 


Regards

Re: adodb one or more connection

PostPosted: Thu Feb 23, 2023 7:41 am
by damianodec
hi Armando,
FW_ReOpenRecordSet is there in FWH 17.09 ?

Re: adodb one or more connection

PostPosted: Thu Feb 23, 2023 7:32 pm
by Armando
Damiano:

If you have FW_OpenRecordSet( oCnSrv, tuple, 1 ), I think yes, you have
the FW_ReOpenRecordSet() function too.

Pls try it


If there is not the FW_ReOpenRecordSet() function, you can try with this code

Code: Select all  Expand view

   IF oDbo <> NIL
      IF oDbo:State() = adStateOpen
         oDbo:Close()
      ENDIF
   ENDIF

   oDbo := FW_OpenRecordSet( oCnSrv, tuple, 1 )  
 



Regards