Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

handle access related error

$
0
0

 Hi all,

I have to run a list of stored procedures. One of them returns error 'The server principal ... is not able to access the database ... under the current security context'. I'm ok with it as I don't have needed access rights yet. What is not ok is that I'd like to handle it using try ... catch block and put the error into the log instead of displaying it in 'Messages' SSMS window. Tried try ... catch like below: 

BEGIN TRY
 BEGIN TRAN
 EXEC [EXAMPLEDB].[EXAMPLESCHEMA].[EXAMPLESTOREDPROCEDURE] @EXAMPLEINPUTPARAMETER
 COMMIT TRAN
END TRY
BEGIN CATCH
 ROLLBACK TRAN
END CATCH

Ok, I will need to put logging stuff into BEGIN CATCH ... END CATCH block as a next step. For now, I would expect that EXAMPLESTOREDPROCEDURE silently fails, but it does display error. 

Please advise.


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>