desconectarse de la red

Post Reply
juan carlos bellucci
Posts: 115
Joined: Sat Mar 07, 2009 9:36 pm
Location: Argentina
Contact:

desconectarse de la red

Post by juan carlos bellucci »

Buen dia Foro.
tengo una duda y quiera saber si alguien tiene la solucion.

Estoy trabajando con un sistema que se conecta a un servidor , hasta aqui todo bien , las bases son del tipo mdb, y el motor
ADOBD El tema es que realizo conexion con cada maquina que trabaja en total son 250 y esto se pone muy lento.

La pregunta concreta es si no hay algo que cierre la cenxion, cuando uso oCone:Close() la conexion sigue abierta.

en algunos lenguajes existe una instruccion disconnect. si alguien sabe como hacerlo desde ya muchas gracias.

Code: Select all


            oCone := CreateObject( "ADODB.Connection" )
            oCone:ConnectionString := "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Data\Sundmastert.mdb;Pwd=" + cPass
            oCone:Open()



 
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: desconectarse de la red

Post by Rick Lipkin »

juan

Ms Access connects very nicely using Ms Jet rather than ODBC. Ms Jet is the OleDb provider native to all Windows machines.

My suggestion is to create your initial connection like this :

Code: Select all

Local xProvider,xSource,xPassword,xString,oConnect
Local oRsStaff,oErr,cSql
Local cDefa

Public oConnection

cDefa := "\\server\volume\share"     // just using a unc if you are not connecting to a local database

xPROVIDER := "Microsoft.Jet.OLEDB.4.0"    // oledb provider for access
xSOURCE   := cDEFA+"\Your.mdb"            // path to access database including the database name   
xPASSWORD := "xxxxxxxx"                   // optional database password 

xSTRING   := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD  // connection string


// create your global connection

oConnect := CREATEOBJECT( "ADODB.Connection" )

TRY
   oConnect:Open( xString )
CATCH oErr
   Saying := "Could not open a Global Connection to Database "+xSource
   MsgInfo( Saying )
   RETURN(.F.)
END TRY

// then use these parameters to open your record sets with the public connection object

oRsStaff := TOleAuto():New( "ADODB.Recordset" )
oRsStaff:CursorType     := 1        // opendkeyset
oRsStaff:CursorLocation := 3        // local cache
oRsStaff:LockType       := 3        // lockoportunistic

cSql := "Select [StaffEid],[Lname],[Fname],[FullName],[Active] From [Staff] "
cSql += "where [Active] = 'Y' Order by Fname,Lname"

TRY
   oRsStaff:Open( cSQL,oCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening Staff table" )
   RETURN(.F.)
END TRY

xBrowse( oRsStaff )
oRsStaff:Close()
 
Now that you have your global connection you can open and close as many recordsets as you like throughout your program and the database will only see one connection.

Tip .. always use the local cache option for best performance.

Rick Lipkin
Post Reply