RSS Forums RSS
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 2221 | Replies: 3
Reply
Join Date: Apr 2005
Posts: 21
Reputation: luisator is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
luisator luisator is offline Offline
Newbie Poster

Help problems with recordset accessing access

  #1  
Jul 19th, 2005
Hi everybody! I am having a strange problem, Im working with a remote access database, i have one application to introduce info to de database and other for making a query. The firt one works perfect...but in the second one the application jumps to the error code when tries to open the recordset. the function I am using is the following:

Private Function Leer_DatoSql(cadena_ejecucion As String) As Variant
'Ejecuta una cadena tipo Transact-SQL según la cadena de conexión
'CONEXION BASICA CON LA BASE DE DATOS acces
'FUNCION QUE SE LLAMA CADA VEZ QUE SE BUSCA UN DATO
'LOS REGISTROS QUE SE TOMAN DE LA BASE DE DATOS SE RETORNAN EN UN OBJETO
'RECORDSET

On Error GoTo error_leer_datosql


'CREACION DEL OBJETO RECORSET
Dim REC As New ADODB.Recordset
REC.CursorLocation = adUseClient
REC.LockType = adLockReadOnly
REC.CursorType = adOpenStatic
'CADENA LA CONEXION DE LA BASE DE DATOS PARA TIPO ACCESS
REC.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=Z:\softphone;" & _
"Uid=usuario;" & _
"Pwd=80234040;"
REC.Source = cadena_ejecucion
REC.Open
REC.ActiveConnection = Nothing

Set Leer_DatoSql = REC

Exit Function
error_leer_datosql:
Set Leer_DatoSql = Nothing
End Function

Please help me!!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 191
Reputation: mnemtsas is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: problems with recordset accessing access

  #2  
Jul 19th, 2005
Posting the error message would be helpful.
Reply With Quote  
Join Date: Jul 2005
Location: Iceland
Posts: 104
Reputation: Alvein is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Alvein's Avatar
Alvein Alvein is offline Offline
Junior Poster

Re: problems with recordset accessing access

  #3  
Jul 20th, 2005
Hi,

Maybe Luis does not know how to do it. -Maybe-. Anyways, a simple MsgBox REC.ActiveConnection.Errors(0).Description at the beginning of the error handler will solve the mistery.

BTW, I've tested the routine here, and it has no problems. But I have to say it's strange the way you "open" a new connection for every recordset to be returned. Because of you are not closing the connection (that would invalidate the Recordset) some resources cannot be freed the right way. One call to Leer_DatoSql() is not a big deal, but surely you plan to call this function many times.

I would suggest you to create a global connection (type is ADODB.Connection), open it right after program's beginning, and close it just before program's end. That way all your recordsets will share the same connection.


Suerte.
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: problems with recordset accessing access

  #4  
Jul 22nd, 2005
Alvein has a real good point about opening and closing connections too frequently. It's been my experience with Access and VB, that doing a large number of opens/query's eats up value processor time, when only one connection is needed.

mnemtsas has a great tutorial on using Access with VB, and it's posted as a sticky thread at the top of this forum.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:55 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC