Check SQL Server login and user functions in a database

Source: Internet
Author: User

Several common creation methods are listed a few days ago. SQL Server Login , Login , User , System stored procedures used by roles and Groups , Of course, you also need to check Connectiongstring String SQL Server Login and database users . The following two functions implement this function. , In essence, it is still used SQL Server For Search and verification. . The stored procedure used is : Sp_helpuser. Detection SQL Server Login is check [Marst] In the database [Syslogins] Table

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

Other related content

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.