Click here to Skip to main content
15,911,306 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL Server networking Pin
Colin Angus Mackay15-Jan-07 22:34
Colin Angus Mackay15-Jan-07 22:34 
GeneralRe: SQL Server networking Pin
JacquesDP15-Jan-07 22:46
JacquesDP15-Jan-07 22:46 
GeneralRe: SQL Server networking Pin
JacquesDP15-Jan-07 22:58
JacquesDP15-Jan-07 22:58 
GeneralRe: SQL Server networking Pin
Colin Angus Mackay16-Jan-07 0:01
Colin Angus Mackay16-Jan-07 0:01 
QuestionRe: SQL Server networking [modified] Pin
JacquesDP16-Jan-07 0:21
JacquesDP16-Jan-07 0:21 
AnswerRe: SQL Server networking Pin
JacquesDP16-Jan-07 17:20
JacquesDP16-Jan-07 17:20 
QuestionBindingSource setting RowState.Modified on unchanged rows! [modified] Pin
nzmike15-Jan-07 17:01
nzmike15-Jan-07 17:01 
QuestionSQLCLR Performance Issue Pin
fodonnel15-Jan-07 14:52
fodonnel15-Jan-07 14:52 
Hi,
I am trying to write a table-valued function in SQL Server 2005 (SP1) to return all active directory groups a user belongs too, using managed code (VB.NET).

Testing the code with a simple winform I get the list of groups in about 0.4 seconds. However the table-valued function takes upwards of 17 seconds to run! Is this normal for managed code in SQL Server?


Imports System
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Collections
Imports System.DirectoryServices
Imports Microsoft.SqlServer.Server

Partial Public Class UserDefinedFunctions

#Region "Constants"
    ''' <summary>
    ''' The connection string for Active Directory.
    ''' </summary>
    'Private Const LDAP_CONNECTION_STRING As String = "LDAP://<My LDAP connection string>

    ''' <summary>
    ''' The LDAP search filter need to find a user in Active Directory.
    ''' </summary>
    'Private Const LDAP_SEARCH_FILTER_USER As String = "(&(objectclass=user)(objectcategory=person)(sAMAccountName={0}))"
#End Region

    ''' <summary>
    ''' Gets all active directory groups for the user.
    ''' </summary>
    ''' <returns>All dataset permissions for the user.</returns>
    <Microsoft.SqlServer.Server.SqlFunction(DataAccess:=DataAccessKind.None, FillRowMethodName:="udfUserActiveDirectoryGroupsFill", TableDefinition:="GroupID NVARCHAR(100)")> _
    Public Shared Function udfUserActiveDirectoryGroups(ByVal userName As String) As IEnumerable

        ' Setup the active directory search.
        Dim searcher As New DirectorySearcher(LDAP_CONNECTION_STRING)
        searcher.Filter = String.Format(LDAP_SEARCH_FILTER_USER, userName)
        searcher.SearchScope = SearchScope.Subtree
        searcher.PropertiesToLoad.Add("distinguishedname")

        ' Run the active directory search. 
        Dim result As SearchResult = searcher.FindOne()
        Dim userEntry As DirectoryEntry = result.GetDirectoryEntry()

        Dim userGroups As New ArrayList
        GetActiveDirectoryGroupsForEntry(userEntry, userGroups)

        Return userGroups
    End Function


    Public Shared Sub udfUserActiveDirectoryGroupsFill(ByVal source As Object, ByRef GroupID As SqlChars)
        GroupID = New SqlChars(CType(source, String))
    End Sub



    ''' <summary>
    ''' Recursively gets the active directory groups for the directory entry.
    ''' </summary>
    ''' <param name="entry">The active directory entry.</param>
    ''' <param name="groups">The list of groups.</param>
    Private Shared Sub GetActiveDirectoryGroupsForEntry(ByVal entry As DirectoryEntry, ByVal groups As ArrayList)
        For i As Integer = 0 To entry.Properties("memberOf").Count - 1
            Dim memberEntry As New DirectoryEntry("LDAP://" + entry.Properties("memberOf")(i).ToString())

            groups.Add(memberEntry.Properties("sAMAccountName")(0).ToString())
            GetActiveDirectoryGroupsForEntry(memberEntry, groups)
        Next
    End Sub

End Class

QuestionSQL DateDiff Question Pin
Hulicat15-Jan-07 14:21
Hulicat15-Jan-07 14:21 
AnswerRe: SQL DateDiff Question Pin
Jon Sagara15-Jan-07 14:25
Jon Sagara15-Jan-07 14:25 
GeneralRe: SQL DateDiff Question Pin
Hulicat15-Jan-07 14:45
Hulicat15-Jan-07 14:45 
Questionmost efficient way to create query... Pin
adairjk15-Jan-07 11:56
adairjk15-Jan-07 11:56 
AnswerRe: most efficient way to create query... Pin
Miszou15-Jan-07 12:28
Miszou15-Jan-07 12:28 
GeneralRe: most efficient way to create query... Pin
adairjk16-Jan-07 3:15
adairjk16-Jan-07 3:15 
GeneralRe: most efficient way to create query... Pin
Miszou16-Jan-07 17:09
Miszou16-Jan-07 17:09 
QuestionSQL Server 2005 Express and Database Diagrams Pin
Miszou15-Jan-07 8:42
Miszou15-Jan-07 8:42 
AnswerRe: SQL Server 2005 Express and Database Diagrams Pin
Colin Angus Mackay15-Jan-07 12:51
Colin Angus Mackay15-Jan-07 12:51 
AnswerRe: SQL Server 2005 Express and Database Diagrams Pin
Pete O'Hanlon15-Jan-07 22:53
mvePete O'Hanlon15-Jan-07 22:53 
Questionusing sp_MSForEachTable to delete data with a where clause [modified] Pin
PrashantJ15-Jan-07 5:10
PrashantJ15-Jan-07 5:10 
QuestionPlease Guide Me Pin
Ashish Porwal15-Jan-07 5:04
Ashish Porwal15-Jan-07 5:04 
Question[Message Deleted] Pin
Orcun Ozturk15-Jan-07 5:04
Orcun Ozturk15-Jan-07 5:04 
AnswerRe: Desktop Database! Pin
Kschuler15-Jan-07 9:51
Kschuler15-Jan-07 9:51 
GeneralRe: Desktop Database! Pin
Orcun Ozturk16-Jan-07 1:53
Orcun Ozturk16-Jan-07 1:53 
GeneralRe: Desktop Database! Pin
Kschuler16-Jan-07 2:57
Kschuler16-Jan-07 2:57 
GeneralDesktop Database! Pin
Orcun Ozturk16-Jan-07 3:07
Orcun Ozturk16-Jan-07 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.