前幾天列出了幾個常用的建立SQL server登陸,登入,使用者,角色和組用到的系統預存程序 ,當然還需要檢查某一Connectiongstring字串所在SQL Server的登陸和資料庫的使用者.下面的兩個函數實現了這樣的功能,其實其實質還是利用SQL server的預存程序進行尋找驗證.用到的預存程序是:sp_helpuser.檢測SQL server登陸是檢查[marst]資料庫中的[syslogins]表
Private Shared Function CheckLogin()Function CheckLogin(ByVal CN As String, ByVal LoginName As String) As Boolean
Dim sql As String
Dim strTemp As String
sql = "Use [master] "
sql += " SELECT [name] FROM [syslogins] Where [Name] = '" & LoginName.Replace("'", "''") & "'"
Try
strTemp = ExecuteScalar(ProviderType.SQL, CN, CommandType.Text, sql)
If Not IsNothing(strTemp) Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
Private Shared Function CheckUser()Function CheckUser(ByVal CN As String, ByVal UserName As String) As Boolean
Dim sql As String
Dim strttemp As String
Dim t As DataTable
Dim dr As DataRow
Dim sUserName, sLoginName As String
sql = "Exec [sp_helpuser] "
Try
t = ExecuteDataset(ProviderType.SQL, CN, CommandType.Text, sql, "t").Tables("t")
For Each dr In t.Rows
sUserName = dr.Item("UserName")
If IsDBNull(dr.Item("LoginName")) Then
sLoginName = ""
Else
sLoginName = dr.Item("UserName")
End If
If sLoginName.ToLower = UserName.ToLower And sUserName.ToLower = UserName.ToLower Then
Return True
End If
Next
Catch ex As Exception
Return False
End Try
Return False
End Function
其他相關內容