vb.net, control if user has right to stored procedure on SQL Server

Before calling a stored procedure I would like to check if the user has rights to it. I use Integrated security and SQL Server 2000, Windows 2003 Server. Or maybe there is a better way to avoid failure in the application if the user has not right to run this SP.

Thanks in advance.
Who is Participating?
rdrunnerConnect With a Mentor Commented:

        Dim oRead As Data.SqlClient.SqlDataReader
        SqlCommand1.Parameters(1).Value = "HILAA"
            oRead = SqlCommand1.ExecuteReader()
        Catch ex As SqlClient.SqlException
            If ex.Number = 229 Then
                MsgBox("No rights on the SP....")
            End If
        Catch ex As Exception

        End Try
Why not just execute it and handle the exception?

If you check if the user has the rights you would have to querry the DB 2 times to get the job done. One time in order to check if he is allowed and once in order to get the work done. This is one wasted trip in case you succeed.

If you just try to execute it and handle the exception properly then you have not wasted a trip to the sql server since you accomplish both questions with one action. An exception is not allwas an evil thing to generate. See it as some information service also. There are places where you can efficently work with errors and i think this is a valid scenario for this :)
lagneskogAuthor Commented:
Thanks rdrunnder

Could you please provide a smal snippet of vb.net code as you thought it would look like.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.