+ Reply to Thread
Results 1 to 7 of 7

Locking Issue using ADO with Excel as a Database

Hybrid View

scott.j.minard Locking Issue using ADO with... 08-15-2016, 06:50 PM
Norie Re: Locking Issue using ADO... 08-15-2016, 06:59 PM
scott.j.minard Re: Locking Issue using ADO... 08-15-2016, 07:01 PM
Kyle123 Re: Locking Issue using ADO... 08-16-2016, 01:06 AM
scott.j.minard Re: Locking Issue using ADO... 08-16-2016, 01:30 AM
Daniele85 Re: Locking Issue using ADO... 08-24-2016, 06:31 AM
Daniele85 Re: Locking Issue using ADO... 08-24-2016, 06:38 AM
  1. #1
    Registered User
    Join Date
    08-15-2016
    Location
    Sydney, Australia
    MS-Off Ver
    2010
    Posts
    3

    Locking Issue using ADO with Excel as a Database

    Hi,

    I currently have an ongoing issue using ADO with Excel as the BE database.
    My application uses an Excel (2010) workbook as a backend to store the required data, then uses another excel workbook to query (Using list objects with data connections) and also manipulate and edit the data in the back end using ADO recordsets. I have used this setup as MS Access is not currently an option, and I need multiple users to be able to manipulate and query data at the same time without read-only restrictions.

    The issue is that occasionally the excel BE database seems to go into a "Locked state". When in this "locked state", the recordset appears to update successfully. However, when I open the BE database or requery with a new ADO connection the changes have disappeared.
    The only way for me to fix this currently is to open the excel BE Database, hit Save and close the workbook.

    The most frustrating part is that most of the time it works without issue.

    Any help would be greatly appreciated. An example of my connection string is below...

     
    Function OpenADODBConnection(strSourceFile As String, HDR As String, IMEX As Integer, ByRef adodb As adodb.connection) As Boolean
    On Error GoTo debugger:
    '----Declare local variables ----------------------------------------------------------------------'
    Dim connString As String
    
    '--------------------------------------------------------------------------------------------------'
    Set adodb = CreateObject("ADODB.Connection")
    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & strSourceFile & _
            "';Extended Properties='Excel 12.0;HDR=" & HDR & ";IMEX=" & IMEX & "';"
            adodb.Open connString
    If Not adodb Is Nothing Then
        OpenADODBConnection = True
    Else
        OpenADODBConnection = False
    End If
    myExit:
    Exit Function
    '----Error Handling --------------------------------------------------------------------------------'
    debugger:
        OpenADODBConnection = False
        
    End Function
    
    Sub test()
    
    Dim adodb As adodb.connection
    Dim rs As New Recordset
    OpenADODBConnection "C:\Users\minasa9\Documents\Matrix Testing\SHUTDOWN PLANNING DATABASE clear.xlsx", "YES", 1, adodb
    
    rs.Open "SELECT * FROM `ORDERS$`", adodb, adOpenKeyset, adLockOptimistic, -1
    
    if rs.recordCount > 0 then rs.movefirst
    
    rs.Fields(1).Value = "Test"
    rs.update
    
    set rs = nothing
    set adodb = nothing
    
    endsub
    Last edited by scott.j.minard; 08-15-2016 at 07:02 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Locking Issue using ADO with Excel as a Database

    Just curious, but why are you using ADO and DAO?

    Can't you do everything in ADO?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-15-2016
    Location
    Sydney, Australia
    MS-Off Ver
    2010
    Posts
    3

    Re: Locking Issue using ADO with Excel as a Database

    Sorry, that was a typo. I am trying to do it all with ADO.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Locking Issue using ADO with Excel as a Database

    Excel isn't multi user, you're going to have these sorts of problems unless you use a database. Why isn't access an option?

  5. #5
    Registered User
    Join Date
    08-15-2016
    Location
    Sydney, Australia
    MS-Off Ver
    2010
    Posts
    3

    Re: Locking Issue using ADO with Excel as a Database

    MS Access is against company policy.
    This is small scale, I am not likely to get more than 2 users at any one time.
    The issues are arriving also arriving during testing when there are not multiple users using the system.


    For example when I run the following code. When the file is in a locked state output reverts back to the original value, even though it successfully updates the value at the start.
    When the database is not in a locked state the output changes to "TestUpdated".
    I hope this makes sense, I have also checked the file attributes to make sure that it is not read only etc.

    Sub CheckDatabaseLocked()
    Dim adodb As adodb.connection
    Dim adodb2 As adodb.connection
    Dim strDBPath As String
    strDBPath = ThisWorkbook.Names("CONNECTION_FILE").RefersToRange.Value   '---Add DB file name here
    
    OpenADODBConnection strDBPath, "YES", 0, adodb
    Dim rsNew As New Recordset
    rsNew.Open "SELECT  `Order` FROM `ScopeInclusion$`", adodb, adOpenKeyset, adLockPessimistic, -1
    rsNew.Fields("Order").Value = "TestUpdated"
    rsNew.Update
    debug.print rsNew.Fields("Order").Value
    rsNew.Close
    
    adodb.Close
    Set adodb = Nothing
    set rsNew = nothing
    
    Dim rs As New Recordset
    OpenADODBConnection strSourceFile:=strDBPath, HDR:="YES", IMEX:=0, adodb:=adodb2
    
    rs.Open "SELECT  `Order` FROM `ScopeInclusion$`", adodb2, adOpenKeyset, adLockPessimistic, -1
    debug.print rs.Fields("Order").Value
    
    rs.close
    adodb2.close
    set adodb2 = nothing
    set rs = nothing
    
    End Sub
    Public Function OpenADODBConnection(strSourceFile As String, HDR As String, IMEX As Integer, ByRef adodb As adodb.connection) As Boolean
    On Error GoTo debugger:
    '----Declare local variables ----------------------------------------------------------------------'
    Dim connString As String
    
    '--------------------------------------------------------------------------------------------------'
    Set adodb = CreateObject("ADODB.Connection")
    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & strSourceFile & _
            "';Extended Properties='Excel 12.0;HDR=" & HDR & ";IMEX=" & IMEX & "';"
            adodb.Open connString
    If Not adodb Is Nothing Then
        OpenADODBConnection = True
    Else
        OpenADODBConnection = False
    End If
    myExit:
    '----Close out objects from memory -----------------------------------------------------------------'
    Exit Function
    '----Error Handling --------------------------------------------------------------------------------'
    debugger:
        OpenADODBConnection = False
        
    End Function

  6. #6
    Registered User
    Join Date
    08-24-2016
    Location
    Camaiore, Italy
    MS-Off Ver
    2013
    Posts
    2

    Re: Locking Issue using ADO with Excel as a Database

    Hi scott,
    i have the same problem... everything seems to work fine (no errors) but after updating, the database (.xlsm file) is always the same.
    Please, let me know if you resolved this problem!
    Daniele

  7. #7
    Registered User
    Join Date
    08-24-2016
    Location
    Camaiore, Italy
    MS-Off Ver
    2013
    Posts
    2

    Re: Locking Issue using ADO with Excel as a Database

    Hi scott,
    i have the same problem... everything seems to work fine (no errors) but after updating, the database (.xlsm file) is always the same.
    Please, let me know if you resolved this problem!
    Daniele

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Access Database and Excel Pivtot Table Issue
    By jefflab1 in forum Excel General
    Replies: 0
    Last Post: 08-11-2015, 11:05 PM
  2. Screen locking issue
    By incommlyndon in forum Excel General
    Replies: 0
    Last Post: 11-08-2013, 11:23 AM
  3. Autofilter issue using macro when locking worksheets
    By rajiraji in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2013, 11:27 PM
  4. Help with macro, automatical locking cells when excel is closed but only locking 1 sh
    By snoopy1461 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2011, 11:29 AM
  5. Excel accessing external database issue
    By wacattack in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-08-2010, 11:44 AM
  6. Issue trying to retrieve records from excel database
    By marktheman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2007, 04:24 PM
  7. [SOLVED] Font issue? Excel locking up.
    By plunk25 in forum Excel General
    Replies: 1
    Last Post: 05-16-2006, 02:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1