Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Data Connection Locks Access DB, Prevents Second Connection's Refresh

I have two data connections to different queries in the same Access DB. The second one always fails (regardless of which I run first).

When I look at the database, I notice that it has a lock file, which I think is causing the problem. It stays locked until I close the Excel file. Can anyone help me to unlock the db as soon as my import is complete?


Additional info:

I'm using Excel and Access 2010.

The error:

"The text file specification 'MyQuery Link Specification' does not exist. You cannot import, export, or link using the specification."

Connection String (note: I'm using Command type: Table):

Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin
;Data Source=A:\folder\folder\My Database.accdb
;Mode=Share Deny None
;Extended Properties=""
;Jet OLEDB:System database=""
;Jet OLEDB:Registry Path=""
;Jet OLEDB:Engine Type=6
;Jet OLEDB:Database Locking Mode=0
;Jet OLEDB:Global Partial Bulk Ops=2
;Jet OLEDB:Global Bulk Transactions=1
;Jet OLEDB:New Database Password=""
;Jet OLEDB:Create System Database=False
;Jet OLEDB:Encrypt Database=False
;Jet OLEDB:Don't Copy Locale on Compact=False
;Jet OLEDB:Compact Without Replica Repair=False
;Jet OLEDB:SFP=False
;Jet OLEDB:Support Complex Data=False
;Jet OLEDB:Bypass UserInfo Validation=False

Lastly, based on this post, I've tried changing my Mode from "Share Deny None" to "Read", but it didn't help. Nor do I understand why it would have, but I tried.

Edit: I've continued to research this issue, but cannot find a solution. I've since tried adding in an additional statement into my connection string, ReadOnly = True but no luck.

like image 899
Aaron Contreras Avatar asked Oct 02 '13 14:10

Aaron Contreras


People also ask

Which of the following options will refresh connections within an Excel workbook?

To refresh specific connections, select one or more connections, and then click Refresh. To refresh all connections in the workbook, clear all connections, and then click Refresh All. To get status information about a refresh operation, select one or more connections, and then click Refresh Status.

How do you refresh a macro in Excel?

You can trigger the refreshing of your stock data by either using keyboard shortcut Ctrl+Alt+F5 or navigating to your Excel Ribbon's Data tab and clicking the Refresh All button within the Queries & Connections button group.

How do you automatically refresh Excel without opening and closing?

To refresh a worksheet, press Ctrl + F5 . To refresh a workbook, press Ctrl + Alt + F5 . To automatically refresh data at regular intervals: Select a cell in the external data range.


1 Answers

I was faced with another issue regarding data connections, and the solution for it actually ended up fixing this long-standing issue as well!

My guess is that the secret lies in "MaintainConnection = False":

Dim i As Integer
Dim awc As WorkbookConnection
Dim c As OLEDBConnection

For i = 0 to ActiveWorkbook.Connections.Count
    Set awc = ActiveWorkbook.Connections.Item(i)
    Set c = awc.OLEDBConnection
    c.EnableRefresh = True
    c.BackgroundQuery = False
    c.Reconnect
    c.Refresh
    c.MaintainConnection = False
Next i
like image 110
Aaron Contreras Avatar answered Sep 20 '22 15:09

Aaron Contreras