Handling a SQL Server Login error msg with VBA?

醉酒当歌 提交于 2020-01-16 17:15:27

问题


I'm working in a VBA module for Access that queries linked tables, generates reports based off the data, and then uses a PDF printer to save the reports to disk. There's a timer in the primary form that will, every N seconds, run an Access query against a "JOBQUEUE" table to see if there are new jobs.

If the database server becomes unavailable, this operation will of course time out. The run-time error of 3051 is being logged, and the loop will try to continue. The loop can't finish, however, because the following error comes right after the VB Run-Time error;

Title is "Microsoft SQL Server Login", so it's not within VB as far as I can tell.

Connection Failed:
SQLState: '01000'
SQL Server Error: 53
[Microsoft][ODBC SQL Server Driver][DBNETLIB][ConnectionOpen(Connect()).
Connection Failed:
SQLState: '08001'
SQL Server Error: 17
[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not 
exist or access is denied.

In every forum & discussion I've found that mentions this error, the asker is concerned with the cause of the error. In this case, I can assume that the error is temporary, and that it needs to continue trying to connect because the installation is unattended. Access goes into a "Not Responding..." state when it's timing out against the DB, and that's OK too, if connection is restored before it goes into the MsgBox described above, it will pick up where it left off and soldier on.

Does anyone know of a way that I can either mute that msgbox, preferably programatically, but I'd take anything at this point that can be done remotely that isn't an RDP session.

Edit: Link to image


回答1:


The error I was getting was indeed not a run-time error that could be caught from code. Rather, it was SQL timing out after I already swallowed & dismissed time-outs in run-time in my VBA module.

The error does not seem to ever appear now that I have introduced a new timer that resets the loop that runs a query against my linked tables. It can't be logged & swallowed, but it can be prevented by being smarter about how I handle timeouts in run-time.



来源:https://stackoverflow.com/questions/15120143/handling-a-sql-server-login-error-msg-with-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!