Solved

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

Posted on 2004-10-25
158 Views
Last Modified: 2010-04-23
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.
0
Question by:lagneskog
    3 Comments
     
    LVL 11

    Expert Comment

    by:rdrunner
    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 :)
    0
     

    Author Comment

    by:lagneskog
    Thanks rdrunnder

    Could you please provide a smal snippet of vb.net code as you thought it would look like.
    0
     
    LVL 11

    Accepted Solution

    by:

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

            End Try
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now