Excel through Access through ODBC Cache DB - locking licenses issue - ms-access

I have an excel workbook set up with 25 sheets in it. Each sheet has a data connection to a query in MS Access. Each access query has one or more linked tables from an InterSystems Caché DB. Here is the connection string from one of them.
Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=\DIR\SUBDIR\XXX\Database\CAST\CAST_CLIENT_SETTINGS.mdb;Mode=Share Deny Write;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Engine Type=5;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
Background refresh is not enabled and the command type is table.
The Access DB has 25 linked ODBC tables to a Cache DB. There are 25 queries in the access db that are each utilizing one or more of the linked tables. Record locks No and Recordset type Dynaset in each.
There is a button with some vba code in the excel workbook that kicks off a refresh of all 25 sheets to bring back the newest information. This works just fine other than taking a few minutes but the issue is that it locks up 25 licenses in Cache and keeps them locked until the workbook is closed.
The company only has 50 licenses so I can't use this many. Is there any setting I'm missing that would stop this from happening? Could I change the mode, the locking mode, the recordset type, background refresh, use a pass through? Could I write something into the vba to remove these locks after it refreshes? People use this utility to track changes they make in the application corresponding to the Cache DB in relatively real time.
Before it gets totally scrapped, I was hoping someone out there would have an idea that allowed it to use only one license if possible. Thanks for your help.

You have to look at the code behind that button how it is doing. I guess it fires off all 25 queries at the same time. You'd probably have to change it to refresh just one and wait until that one is finished before refreshing the next.

I know that this is a very old post, but by default Excel keeps OLEDB/ODBC connections open (thus locking the access database in use.)
No amount of configuration via connection string will stop Excel from doing this. Contrary to expectations, setting the mode to share deny none, or read only won't get you past the trouble. However, you can modify the properties of the connection via code, to prevent this behavior using the .MaintainConnection property. There is no setting in the UI to modify this property.
Try this code:
Function unlock_conns()
Dim conn
For Each conn In ActiveWorkbook.Connections
Select Case conn.Type
Case xlConnectionTypeOLEDB
conn.OLEDBConnection.MaintainConnection = False
Case xlConnectionTypeODBC
conn.ODBCConnection.MaintainConnection = False
End Select
Next conn
End Function

Related

Ms access database with MySQL as the backend

My current team of 20 people uses an access database front end on their desktop. The backend of the access database is on a network drive. I have been asked to create an access database front end with MYSQL as the back end.
I have installed the MySQL workbench and the ODBC connector on my computer. I have created the schema and tables and I have connected the front end of the database connected to the MYSQL table I created in workbench. My question is
How do I deploy this for the team to use. I believe I can move the front end of the access dB to the network drive and the team can copy it to their desktop. But what do I do about the backend?
Does the team need to have the ODBC connector installed on their computers?
Should I move the MySQL workbench to the network drive?
PS: I am a new developer and just learning about databases and I am only familiar with the access database please go easy on me.
Thanks.
SO is for questions about coding, so this is OT. However:
One method is described in my article:
Deploy and update a Microsoft Access application with one click.
The old backend, you can archive. It will not be used anymore.
Yes.
Probably not. It is only for you, should you need to modify the
MySQL database.
Well, first up, you STILL need and want to deploy the application part called the front end (FE) to each workstation.
So, after you migrate the data to MySQL, then of course you will use the access linked table manager, and now link the tables to MySQL. How this works is really much the same as you have now. The only difference is that you linked tables now point to the database server (MySQL). From the application point of view, it should work as before.
Like all applications, be it Outlook, Excel, accounting packages? You STILL deploy the application part to each workstation. So just because YOU are now developing and writing software with Access does not mean out of the blue that you now for some strange reason STOP deploying the FE part to each workstation. In fact, you should be deploying a compiled version of your application (a accDE).
A few more tips:
WHEN you link the FE, MAKE SURE you use a FILE dsn. The reason for this is Access converts the links to DSN-less for you. What this means is that once you link the tables, then you are free to deploy the FE to each workstation and it will retain the linked table information WITHOUT you having to setup a DSN connection on each workstation. You will also have to of course deploy the MySQL ODBC driver to each workstation as that is not part of Access nor it is part of your application.
So just because you are now developing software does not suggest nor get you off the hook of deploying that application to each workstation. So, your setup you have now with a FE on each workstation does NOT change one bit.
For the most part, after you migrate the data to MySQL, then likely setup your relationships (say with MySQL workbench) there are several other things you need to keep in mind.
All tables now need a primary key. You likely have this, but Access with a access back end did and could work on tables without a PK. However, for SQL server/MySQL etc., then all tables need that PK.
Next up:
If you have any true/false columns, you MUST set a default up for that column. If such true/false columns have a default value or allow nulls, this will confuse access - so ensure that true/false columns can't have nulls and have default (useally 0) setup on the server side.
Add a "rowversion" column. This is not to be confused with a datetime column. In SQL server this rowversion column is of timestamp data type (a poor name, since the column has zero to do with time - it is simply a column that "versions" the row. This will also eliminate many errors. I don't know what this type of column is called in MySQL, but all tables should have this column (there is zero need to see/use/look at this column on your forms - but it should be part of the table.
All of your forms, reports and code should work as before. For VBA recordset code, you need this:
dim rst DAO.Recordset
dim strSQL as string
strSQL = "SELECT * from tblHotels"
set rst = currentdb.OpenRecordSet(strSQL).
You likely in the past had lots of code as per above.
You now need:
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
You can generaly do a search and replace (find each .OpenRecordSet, and add the dbOpen and dbSee to each line of code you find. (I put the dbOpenDynaset, dbSeeChanges in my paste buffer. And then do a system wide search. It takes a few minutes at most to find all .openRecordSets
At this point, 99% of your code, forms and everything should work.
The ONE got ya?
In access be it on a form or in VBA recordSet code? When you create a new row, or start typing on/in a form? Access with access back end would generate the PK at that point. There was/is no need to save the record to get the PK value. This need is rare, and in a large application I only had about 2 or 3 places where this occured.
So, if you have code like this:
dim rstRecords as RecordSet
dim lngPK as Long ' get PK value of new record
Set rstRecords = CurrentDb.OpenRecordset("tblHotels")
rstRecords.AddNew
' code here sets/ add data/ set values
rstRecords!HotelName = "Mount top Hotel"
rstRecords!City = "Jasper"
' get PK of this new record
lngPK = rstRecods!ID ' get PK
rstRecords.Update
So, in above code, I am grabbing the PK value. But with server systems, you can NOT get the PK value until AFTER the record been saved. So, you have to change above to
rstRecords.Update
rstRecords.Bookmark = rstRecords.LastModified
' get PK of this new record
lngPK = rstRecods!ID ' get PK
Note how we grab/get the PK AFTER we save.
The bookmark above simply re-sets the record pointer to the new record. This is a "quirk" of DAO, and WHEN adding new reocrds, a .Update command moves the record pointer, and thus you move it back with the above .LastModified. You ONLY need the .LastMOdifed trick for NEW reocords. For existing, you already have the PK - so it don't matter.
This type of code is quite rare, but sometimes in a form (and not VBA reocdset code), some form code we might use/need/get/grab the PK value. In a form, you can do this:
if me.dirty = true then me.dirty = false ' save reocod
lngPK = me.ID ' get PK
So, once again, in the above form code, I make sure the record is saved first, and THEN I grab the PK value as above. Of course this is ONLY a issue for NEW records. (and you don't have to use the bookmark trick - that's only for recrodsets - not bound forms.
So, just keep in mind in the few cases when you need the PK value of a NEW record, you have to do this AFTER you saved the recordset (update) or in the case of a form, after you forced a form record save. This requirement is only for new records and ALSO only when your code needs to get/grab the new PK value.
Other then the above two issues? All the rest of your existing code and forms should work as before.

ODBC Driver Connect auto fill

I have an Access Database connected(linked table) to an Oracle database.
I wrote some Select queries. Everytime I run it, I get an "Oracle ODBC Driver Connect" input box.
Is there way to write a vba macro to enter username and password (auto fill) and Enter Ok.
Trying to set up an auto run for macros in this Access db.
Any help is appreciated.
As pointed out, when you link the tables, you are given an option to save the password in those table links. If you missed this step, then you will get that ODBC prompt.
THIS HAS ZERO to do with you writing select queries. The simple matter is try clicking on one of the linked tables you use in such quires. Either you get an ODBC prompt or you do not.
If you do, then of course you going to get such a prompt when you write a query. YOU WANT to FIRST get the table links working without an ODBC prompt and THEN write those queries based on the linked tables.
So get the linked tables working first. Forget about and don’t’ worry about your queries you are writing. Until such time that a simple click on (opening) a linked table works and does not throw out the ODBC prompt, then you are looking at the WRONG problem.
Once you get your linked tables working without a prompt, then your queries will also work without a prompt.
So you have two choices to fix this problem.
Simple re-link your tables, and ensure that you select [x] check box during re-link to save the password.
The prompt you missed and want to select is this one:
Now if your tables are already linked and you run the linked table manger, you WILL NOT get this prompt anymore. So you have to delete the table links, and re-create.
Of course deleting the table links can often result in the linked table names being changed, and that can be a pain, especially if you have a LOT of linked tables. Only you can make this judgement call as to what is less work. If you have just a few tables, then just delete them, and use the external data -> then in the import and link secton, choose ODBC and you can add the tables, but REMEMBER to select (check) the above save password box as per above that you missed.
Now, most people over time wind up with some table re-link code VBA. So if you have suc re-link code already working and handy, then simply re-run that code with the user/password included in the connection string you use in that code. Of course if you don't have such code, then the above linked table manager in Access is a code free solution and is obviously your best choice and course of action.
So in place of above, you can find some table re-link code that will force (save) the user/id in the table links for you.
However, if you don’t want to delete + re-create all those tables, and you don’t have already setup some re-link code, there is also another (3rd) choice.
In your application start-up code simple execute a one-time logon. If you do this, then the ODBC prompt will not appear when you use the linked tables and hence also not appear when you attempt to run/build/use a query based on those linked tables.
The code to execute a one-time logon will look like this:
Function TestLogin(strCon As String) As Boolean
On Error GoTo TestError
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb()
Set qdf = dbs.CreateQueryDef("")
qdf.connect = strCon
qdf.ReturnsRecords = False
'Any VALID SQL statement that runs on server will work below.
' this does assume user has enough rights to query built in
' system tables
qdf.sql = "SELECT 1 "
qdf.Execute
TestLogin = True
Exit Function
TestError:
TestLogin = False
Exit Function
End Function
Above code run ONE time on start-up of your application will thus eliminate the ODBC prompt(s) when you click on a linked table. And of course once that issue of linked tables is resolved, then of course creating or clicking on your query or running those quires will now ALSO work without the prompts.
You can NOT auto fill that prompt, you have to take CORRECT steps in the first place to PREVENT that prompt from appearing. So to answer your question?
No, you can't write code to enter the requested prompt, but if you link your tables with the password saved, or execute the above logon code, the prompt will NOT appear in the first place.

Is it safe to frequently Compact and Repair Access DB?

I have an Access Database which I populate using a pass through query.
I get specific data from an SQL database and dumps it on Access.
This Access DB is updated weekly but I cannot simply append new data from the previous week because all other past weeks also updates.
What I did is truncate the Access DB and then load everything again.
When I do that, I need to Compact and Repair the DB so that the size doesn't bloat.
My question is, is it ok to do that? Currently I am using the logic posted in this answer.
I have not encountered any problems yet but I just want to make sure and get our access guru's thought about it. Also I'm planning on doing a scheduled run on our server to do the task.
Just need to make sure that it will not get corrupted easily (what is the chance of corrupting the file in the first place?).
If you'll ask, why do I need to do this? Users of data have no access on SQL server.So I have to pull data for them so they can just connect to Access DB instead.
Just in case you need the code:
Dim sqlDelete As String
Dim sqlAppend As String
sqlDelete = "DELETE * FROM dbo_Table;"
sqlAppend = "INSERT INTO dbo_Table (Col1,Col2) SELECT Col1,Col2 FROM passThrough;"
With DoCmd
.SetWarnings False
.RunSQL sqlDelete
.RunSQL sqlAppend
.SetWarnings True
End With
Application.SetOption "Auto Compact", True
If you need to truncate the data and load again I would recommend to move all tables, which should be truncated and all temporary tables to separate database.
After separating it will be possible to replace this database with unnecessary data by empty database file when the application starts. Just save a copy of empty database and copy this file over existing database with old data. This should be done before opening any form/recordset based on tables from temp database. It will work faster than C&R each time and more reliable, because sometimes C&R may damage the file.
Template database file also can be stored in main database in Memo field
I will refer this forum post: http://www.utteraccess.com/forum/index.php?showtopic=1561733

SQL Server rows not editable for Access after Insert

I have this problem: I'm using a SQL Server 2008R2 backend and MS Access 2000 frontend where some tables are connected via ODBC.
Following Structure (Tables all on SQL-Server):
Import (not connected to Access)
Products (connected via ODBC to Access)
Pricing (connected via ODBC to Access)
I want to fill the Pricing table automatically with some data from Products and Import. This is supposed to run as a SQL Agent job with a T-SQL script.
I want to insert the data from "Products" with following command:
INSERT INTO Pricing (Productnr, Manufacturernr)
(SELECT Productnr, Manufacturernr
FROM Products
WHERE Valid = 1
AND Productnr NOT IN (SELECT Productnr FROM Pricing ));
Right after that the inserted rows are locked for Access, I can't change anything. If I execute sql queries with SQL Server Management Suite or if i start queries as SQL Agent jobs everything works fine.
Why are the rows locked in ms access after the query ran (even if it finished successfully)? and how can I unlock them or make it unlock itself right after the query/job ran?
Thanks
When SQL Server inserts new rows, those new rows are in fact exclusively locked to prevent other transactions from reading or manipulating them - that's by design, and it's a good thing! And it's something you cannot change - you cannot insert without those locks.
You can unlock them by committing the transaction that they're being inserted under - once they're committed to SQL Server, you can access them again normally.
The error message i get says, that the dataset has been changed by another user and if i save it, i would undo the changes of the other user. (and asks me for copying into clipboard).
This is different from "locked", and completely normal.
If you have a ODBC linked table (or form based on the table) open, and change data in the backend, Access doesn't know about the change.
You need to do a full requery (Shift+F9) in Access to reload the data, afterwards all records can be edited again.
Got the solution for my Problem now.
I had to add a timestamp row into the pricing table, so access could recognize the change.
Access loads the data into the front end when the table is first accessed. If something in the backend changes the data, you need Access to refresh it first, before you can edit it from the front end (or see the changes).
Do this by (in Access) by closing and reopening the table, or switching to the table and pressing shift-F9 as Andre suggested, or programmatically using a requery statement. You must requery, not refresh, for it to release the locks and register the changes made in SQL.

solution needed - 2 users running a program

So I've developed this Access 2007 application with about 2 forms, a lot of VBA code and a bunch of tables.
Now the business wants to run this off a network drive (call it G:\ for example). My current solution (which I've already implemented is have a table similar to:
__________________
|Setting | Value |
==================
Updating 1
UpdateBy User1
So let me give you a context. When the application runs there is a button called "update" which updates the local table from a remote server so we can apply filtering. Now when two people (user1, user2) launch the application, and one person clicks update then the updating field is set to true, and the updateby is set to their name.
So User number 2 tries to update, it checks if the updating field is true, if it is then it gives them a message (to user two, not to user one).
It works beautifully right now, but here is the problem: Lets say user1 is updating, and closes his program (or taskkills it) or the power disrupts, then the application shuts off with the updating field set to to true. Now no matter who launches it, they can not update because its "already updating"
Can you guys think of a solution to this? Maybe a workaround?
Consider a different locking strategy. In the click event of your "update" button, you can first open a recordset based on your tblUpdateStatus (the table where you've been writing UpdateBy) with dbDenyWrite + dbDenyRead options.
Set rst = db.OpenRecordset("tblUpdateStatus", _
dbOpenTable, dbDenyWrite + dbDenyRead)
Then do your other operations for the "update" button. Afterward, close and release the recordset ... which releases the tblUpdateStatus lock.
Trap the error when a user is unable to open the recordset (because another user has the table locked), give them a message to try later and exit your click event subroutine.
With this approach, when user1 locks tblUpdateStatus but exits Access uncleanly, her lock on tblUpdateStatus is released. You may not even need to update tblUpdateStatus unless you want to record which user has it locked.
See Create and Use Flexible AutoNumber Fields (from the Access Cookbook) for more details about using a recordset with dbDenyWrite + dbDenyRead.
Please do not run an Access application with more than one user when you have not split the database. It will cause endless trouble. The data portion (back-end) should be put on the server and the code and forms (front-end) should be put on each users desktop.
More information: http://support.microsoft.com/kb/162522
Read my article on why you split here:
http://www.members.shaw.ca/AlbertKallal/Articles/split/index.htm
In the above, I don't just tell you to do this, but I tell you WHY you split.
It should help you a lot in terms of users tripping over each other.