开发者

How do I suppress the ODBC dialog box on a DSN-Less connection?

开发者 https://www.devze.com 2023-03-27 11:37 出处:网络
I am trying to access a MySQL table via a DSNless ODBC connection from Microsoft Access. I ave no problem actually connecting is a valid user name and password is provided. Howeve开发者_如何学Pythonr

I am trying to access a MySQL table via a DSNless ODBC connection from Microsoft Access. I ave no problem actually connecting is a valid user name and password is provided. Howeve开发者_如何学Pythonr in either of these are not valid, the ODBC dialog screen appears asking for connection details. Is there any way of stopping the ODBC dialog screen from appearing and just letting the connection error?

My ODBC connection string is

"ODBC;Driver=MySQL ODBC 3.51 Driver;SERVER=XXXX;DATABASE=XXXX;UID=XXXX;PWD=XXXX;Option=3"


This FLAG_NO_PROMPT idea actually works. In the connection string you usually have something like "ODBC;DRIVER=.......; OPTION=3"

Just add 16 for FLAG_NO_PROMPT, i.e. use OPTION=19, and it will suppress the system prompt.


Take a look at - 19.1.4.2. Connector/ODBC Connection Parameters

Specifically, the "options" parameter and its flag "FLAG_NO_PROMPT"...


You may be able to stop it with a "DoCmd.SetWarnings False".

Another option is to try "On Error Resume Next" at the beginning of the procedure. You could do a check in the code for the "ODBC call failed" error (I think err.number = 3151). Just put an if right after you try to connect to the ODBC, if it fails, send it to an exit.

On Error Resume Next
Dim db As DAO.Database 'Will also work with ADO
Dim ODBCstr As String

Set db = 'Connect with ODBC here

If Err.Number = 3151 Then 'Could also try If Err.Number <> 0 Then
   GoTo Exit_ThisCode
End If

That may work, as long as an error is actually being thrown when it fails to connect. If you choose to check with a specific error code, just make sure you know the right one.


I don't know if it will help you but the actual argument to the ODBC API SQLDriverConnect which stops dialogue boxes being displayed is SQL_DRIVER_NOPROMPT. However, you should be warned that not all drivers follow the specification exactly. I don't know how you get MS Access to call SQLDriverConnect with SQL_DRIVER_NOPROMPT - sorry.


If someone is going the DSN route, there is a checkbox under Details that sets the same option: "Don't prompt when connecting"

How do I suppress the ODBC dialog box on a DSN-Less connection?

0

精彩评论

暂无评论...
验证码 换一张
取 消