First of all, I don't know if that's the correct place for this post, if not any admin feel free to move it.
I have an Access 2013 database working great for the most part. I've recently written a VBA module to insert the data from Active Directory to the DB (mostly to include and/or update user data, emails/telephones and such). The module works great but after running it, the Access DB remains locked. It worked alright a couple of times (since I ran it a handful of times to retrieve and update all the info I wanted, changing target OUs and such) without any meaningful changes to the code (at least to the code that might be locking the DB) but most of the times it leaves the DB locked and unable to save changes until I close and reopen the DB again.
(Sorry it's in Spanish. It basically says "You don't have exclusive access to the database at this moment. If you continue making changes you might not be able to save them" or something in the line of that)
Now, the code is pretty simple. It opens a LDAP connection, retrieves the needed data through a LDAP query I edit to get the info I need, sets up a SQL transaction with all the SQL instructions required and it commits the transaction or rollbacks it if there's any error. In both cases LDAP connection is closed. Those are the two things that I guess could be leaving the DB locked and both are dealt with correctly. Here's an example of the code
Any idea where the DB might be getting stuck? It's not that big of a deal as it happens with some function I only plan to launch manually and it fixes by reopening the DB (and the changes made by the transaction do apply and save) but I'd prefer to have it fixed.Code:Private Sub marcarUsuariosActivos() Set Conn = CreateObject("ADODB.Connection") Set iAdRootDSE = GetObject("LDAP://RootDSE") 'especificamos el dominio y opcionalmente contenedor strDefaultNamingContext = ' domain and containers I want to check Conn.Provider = "ADsDSOObject" Conn.Open "ADs Provider" strQueryDL = "<LDAP://" & strDefaultNamingContext & ">;(&(objectCategory=person)(objectClass=user));samAccountName" Set objCmd = CreateObject("ADODB.Command") objCmd.ActiveConnection = Conn objCmd.Properties("SearchScope") = 2 ' Todo el arbol a partir del contenedor especificado objCmd.Properties("Page Size") = 500 objCmd.CommandText = strQueryDL Set objRS = objCmd.Execute dao.DBEngine.BeginTrans On Error GoTo error_Trans sqlUpdate = "Update Usuarios set Activo = no" CurrentDb.Execute sqlUpdate, dbFailOnError 'Recorremos los resultados While Not objRS.EOF 'Activamos la casilla de activo para el usuario que coincida con el resultado leido de AD sqlUpdate = "Update Usuarios set Activo = yes WHERE Usuario_windows='" & objRS.Fields("samAccountName") & "'" CurrentDb.Execute sqlUpdate, dbFailOnError objRS.MoveNext Wend dao.DBEngine.CommitTrans Conn.Close Exit Sub error_Trans: dao.DBEngine.Rollback MsgBox "Error en la transacción: " & Err.Description Conn.Close Exit Sub End Sub
Thank you so much