Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access with 1 MySQL Table asking for credentials

I have a access database using a local sql server backend for all tables except 1 web based MySQL table. The MySQL table has 50 rows or so, 3 fields, not big at all. I have a odbc connection setup and the table is linked with the password saved. This table is updated 30 times per day at most... Sometimes the connection breaks and the MySQL connection popup will appear... clicking test will result in a success, and clicking ok will allow the code to proceed. It is doing a 1 line update (SET LastUpdatedDate = #" & now() & "# WHERE ItemID = 'xyz').

I want to capture an error, or get it to continue without the connection if it is unavailable... but it appears no error is generated. I would rather not update the table when this happens, then have to physically select ok to get it running again. This problem exists from multiple locations, on multiple PCs around the US. I assume it is the server the MySQL db is hosted on that is having problems - I just want to know how to ignore them and move on with the other code... again, no error generated (So On Error ... won't work). Any Ideas? Using Access 2016.

UPDATE: My current setup is to ping the server... and if the ping gets a response, I assume it is up... then I run 'CurrentDb.Execute "UPDATE XYZ SET ABC = 'DEF' WHERE GHI = 'JKL'". That simple. If I try to query the table XYZ and it isn't available, I get the same connection popup. How should I go about refreshing the table? Delete the link and recreate?

NEW UPDATE Finally got around to try out the DSN-less pass through query proposed by Andre below. When I get to the 'execute' step I get an error saying I cannot execute a select query... but it is an update query. Here is the SQL string... .SQL = "UPDATE [Status] SET ItemDate = NOW() WHERE PlantID = '" & PlantID & "' AND ItemID = '" & ItemID & "'"

like image 577
riley3131 Avatar asked May 12 '19 17:05

riley3131


People also ask

In which table does MySQL store passwords for user account?

MySQL stores credentials in the user table in the mysql system database.

How do I find MySQL database credentials?

In your local system right, go to this url : http://localhost/phpmyadmin/ In this click mysql default db, after that browser user table to get existing username and password.

Can a MySQL user have multiple passwords?

As of MySQL 8.0. 14, user accounts are permitted to have dual passwords, designated as primary and secondary passwords.

Could not connect to MySQL with the given password while installing?

Have you tried completely removing the software (from your drive, Firewall, the relevant ProgramData files, the registry), and then reinstalling it? Please do so, reboot your system and try starting the software.


1 Answers

I suggest that instead of running an Access query on the linked table, you use a DSN-less Pass-Through query that you create on the fly.

This should either always work, or raise a trappable error.

Const ConnectString = "ODBC;DRIVER={MySQL ODBC 5.1 Driver};SERVER=your.server.com;PORT=3306;DATABASE=mydatabase;UID=myuserid;PWD=mypassword"

Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.CreateQueryDef("")
With qdf
    ' Setting .Connect turns it into a Pass-Through query
    .Connect = ConnectString
    ' Need to set this for non-SELECT queries
    .ReturnsRecords = False
    ' Note: you need to use MySql syntax here, not Access SQL, especially the correct date format
    .SQL = "UPDATE XYZ SET ABC = 'DEF' WHERE GHI = 'JKL'"
    ' or since MySql has a NOW() function too, just this:
    .SQL = "UPDATE foo SET LastUpdatedDate = NOW() WHERE ItemID = 'xyz'"
    .Execute
End With

You can also try a saved Pass-Through query, it might work as well. Then you would only need to supply the current .Sql, not the connect string.

like image 97
Andre Avatar answered Sep 30 '22 17:09

Andre