Excel Vba handling errors from Ado Connections/permissions to SQL server.

robtyketto

Board Regular
Joined
Oct 25, 2006
Messages
111
Hi All,

My spreadsheet is a front-end for users to execute queries/store procs against SQL server databases and output the rowset(s) to worksheets, this is all working well.

It's the error handling I want to improve, currently my error handling consists of the usual "On error" and displays the vba Error Number and description, which works well in displaying a suitable message when the server is unavailable or an invalid Server or database has been specified in the connection string, the problem I want to specifically capture is if the user doesn't have permission to the database (trusted connection/windows credential based in the connection string).

I've printed both the excel and the ado error details, but if a users don't have permission to a database it's attempting to run a command against it appears to bypass the "On error" error handling and a message box appears displaying the error icon and just the text "5" (from memory) rather than the full details I've specified.

Has anyone experience of specifically capturing/checking error codes related to SQL permissions?
I did read that Excel vba can't capture some Ado errors but found nothing concrete.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top