Resumen Acceso multiusuario a Access

Mensaje enviado por Quintero Rojas Daniel <dquintero@meximed.com>

Por si a alguien le interesa:

Multiples Simultaneous Users Support With Access

Category: Databases/ Data Access/ DAO/ ADO
Level: Intermediate

Description: This Article shows you how to create font end Applications that use an access database, in a situation in which your program will be running on multiple computers at once, and accessing the same database. This Uses ADO 2.6

Compatibility: VB 6.0
Submitted on 10/6/2001 11:51:40 PM and accessed 25 times.

Multi User Access Databases
I am assuming that you already have a reference to an ADO connection object, and that the connection to the database has been opened. Lets call the ADO Connection object ActiveConn. For those of you who are already lost, here is how to open a connection to a database:

Public ActiveConn As ADODB.Connection
Dim strconnect As String
Dim strProvider As String
Dim strDataSource As String

strProvider = "provider= Microsoft.Jet.OLEDB.4.0;"
'(Data provider. 4.0 is access 2k. They are backwards compatible, so use 2k for
'everything)
strDataSource = "Data Source=" & path
'(This is where you put in the path to the database; including the database name, and file
'extension)
strconnect = strProvider & strDataSource
'(Just put the 2 together)
Set ActiveConn = New ADODB.Connection
'(Create a new connection object)
ActiveConn.CursorLocation = adUseClient
'(Use the client cursor)
ActiveConn.Open strconnect
'(Open the connection)

There, just know that this will open a connection to the specified database
Now, lets move on to the important stuff.
This is how you open a connection to a record set in the connection that you just opened..

Public Rset As ADODB.Recordset
Set Rset = New ADODB.Recordset
'(Create a new connection object)
Rset.CursorType = adOpenStatic
'(Some sort of a cursor doodad)
Rset.CursorLocation = adUseServer
'(This makes it so that the connection requires less network resources)
Rset.ActiveConnection = frmmain.ActiveConn
'(Tell the record set object what connection to open the table for)
Rset.Open "Select * From Rset", frmmain.ActiveConn, adOpenDynamic, adLockPessimistic
'(Do the opening)

There, now that we have opened the record set, let me explain what is happening. The cursor location setting specifies where the data is stored. If it is set to client, then the data from the “server” (table) is basically copied over to the local machine, and periodically updated in the actual table. Setting it to server makes sure that it is updated more frequently, because the data is not copied to the local machine. This way all of your users have the most current data.

AdLockPessimistic, specifies the type of record locking. This just makes sure that only one user is accessing any record in the database at any given time. This is very important to avoid getting errors, which you will get if 2 people try to edit the same record at the same time. Another thing that you need to know, is that if you try to edit a locked record, you will get an error. Handling that is covered next.

Now for the actual database data editing.
At to top of the procedure at which you are going to edit the data, add the following:

On error goto err

Then at the bottom of the procedure, add this:

Exit Sub (Make sure that the error code does not get run when there is no error)
Err:
Rest.close '(Close the database)
Rset.open '(Open the database)
Resume '(Resume with the line that caused the error).

There you go, that is all that there is too it. I just submitted this, because I had to call Microsoft Tech Support to find this out…I could not find it anywhere on PSC. So there you have it. Please vote and all of that other stuff. Leave feed back.
P.S. If you are having a lot of trouble with some coding thing, call Microsoft. The number is on the Microsoft web site. Microsoft tech support is great.


Lic. Daniel Quintero Rojas
Tel. Oficina (Meximed): (52) 5448-6700 Ext. 6913
E-mail: dquintero@meximed.com
      dqrsoftware@gmx.net
     dqrsoftware@hotmail.com
Página web: http://dqrsoftware.tripod.com/
¡SALUDOS DESDE MÉXICO!



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com