The
ProgrammingMSAccess.COM Site
This procedure
demonstrates how to Print login metadata to the immediate window with the
help of a datareader.
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
'Connect to local SQL Server
Dim cnn1 As SqlClient.SqlConnection = _
New SqlClient.SqlConnection _
("Data Source =(local);Integrated Security=SSPI")
cnn1.Open()
'Create datareader that returns field names from the
'sp_helplogins resultsets
Dim cmd1 As SqlClient.SqlCommand = _
New SqlClient.SqlCommand("Exec sp_helplogins", cnn1)
Dim drd1 As SqlClient.SqlDataReader = _
cmd1.ExecuteReader
'Print login name and whether a user name is
'associated with the login name
Do While drd1.Read
Console.WriteLine(drd1.GetString(0) & _
StrDup(30 - Len(drd1.GetString(0)), " ") & _
drd1.GetString(4))
Loop
'Print login name, default database name, user
'or role name in default database, whether row
'is for a user or role
drd1.NextResult()
Console.WriteLine()
Do While drd1.Read
Console.WriteLine(drd1.GetString(0) & _
StrDup(25 - Len(drd1.GetString(0)), " ") & _
drd1.GetString(1) & _
StrDup(25 - Len(drd1.GetString(1)), " ") & _
drd1.GetString(2) & _
StrDup(25 - Len(drd1.GetString(2)), " ") & _
drd1.GetString(3))
Loop
cnn1.Close
End Sub
Learn more about VB.NET programming from either
Programming Microsoft SQL Server 2000 with
Microsoft Visual Basic .NET or
Programming Microsoft Visual Basic .NET for Microsoft Access Databases.
Copyright 2003 CAB, Inc. All rights reserved. Republication or redistribution
of CAB, Inc. content, including by framing or similar means, is expressly
prohibited without the prior written consent of CAB, Inc. CAB, Inc. shall not be
liable for any errors in the content, or for any actions taken in reliance
thereon.