PC Review


Reply
Thread Tools Rate Thread

Checking permission rights using SQL Server Stored Procedure and return values

 
 
Scott
Guest
Posts: n/a
 
      1st Oct 2006
With advice from the usegroup, I was able to solve a problem I had.
(Specifically, my thanks to Doug Steele, who is an invaluable resource
on this usegroup.) I thought I would share my result, in case it helps
someone.

I use permission groups from our corporate security setup to control
access rights to data in my adp. I needed a stored proceedure that
would check if a user is a member of a group. Here is what I've come up
with. I hope it helps someone in the future

This is the VBA code, with the T-SQL stored procedure referenced as a
comment:
'---------------------------------------------------------------------------------------
' Procedure : fctCheckGroupMembership
' DateTime : 10/1/2006 08:39
' Author : Scott
' Purpose : Check membership in a global group using
' SQL server's access to group permissions
' Inputs : Requires the group name, using format
' [domain]\[group name]
' Outputs : Function returns 0 if user is NOT a member of the group
' Returns 1 if the user IS a member
' Returns 3 if the group cannot be found
' Requires : SQL Server stored procedure named uspCheckMembership.
'
' ***************uspCheckMembership*************************
' --Script Date: 10/1/2006 8:18:09 AM
' --Name: dbo.uspCheckMembership
' --Purpose: Checks to see if the user running the stored
' -- procedure is a member of the requested group
' --Inputs: Requires the @Group parameter.
' -- This should be passed in the format:
' -- [DOMAIN]\[USER GROUP]
' --Outputs: Returns 0 if user is NOT a member of the group
' -- Returns 1 if the user IS a member
' -- Returns 3 if the group cannot be found
'
' CREATE PROCEDURE dbo.uspCheckMembership (@Group varchar(60))
' AS
'
' DECLARE @IsMemberStatus as varchar(20)
' SELECT @IsMemberStatus = IS_MEMBER(@Group)
'
' IF @IsMemberStatus IS NULL
' Begin
' Print 'No Such Group'
' RETURN 3
' End
' Else
' Begin
' PRINT @IsMemberStatus
' RETURN @IsMemberStatus
' End
' GO
'

Function fctCheckGroupMembership(strGroupName As String)

Dim conCurr As ADODB.Connection
Dim cmdCurr As ADODB.Command
Dim intReturnValue As Integer


'On Error GoTo fctCheckGroupMembership_Error

Set conCurr = CurrentProject.Connection


Set cmdCurr = New ADODB.Command
cmdCurr.ActiveConnection = conCurr
cmdCurr.CommandText = "uspCheckMembership"
cmdCurr.CommandType = adCmdStoredProc
cmdCurr.Parameters(1) = strGroupName
cmdCurr.Execute
Debug.Print "fctCheckGroupMembership returned " &
cmdCurr.Parameters(0)
intReturnValue = cmdCurr.Parameters(0)
fctCheckGroupMembership = intReturnValue

On Error GoTo 0
Exit Function

fctCheckGroupMembership_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure fctCheckGroupMembership of Module modCheckGroupMembership"

End Function

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure return values George Microsoft ADO .NET 3 22nd Dec 2008 02:03 PM
Stored Procedure Return Values Adam Knight Microsoft ASP .NET 3 14th Dec 2005 07:56 AM
Accessing RETURN values from a Stored Procedure PeteZ Microsoft C# .NET 1 1st Sep 2003 05:57 AM
Accessing RETURN values from a Stored Procedure peteZ Microsoft ADO .NET 1 1st Sep 2003 05:42 AM
Stored Procedure return values Paul Microsoft ADO .NET 2 6th Aug 2003 08:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:53 AM.