how to login from VB into sql server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adnan amin
    New Member
    • Jan 2007
    • 8

    how to login from VB into sql server

    i need help how to login from VB into sql server using sql server account
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    1. In VB go to Project – References and check Microsoft ActiveX Data Object 2.1 Library.
    2. I made it as simple as possible. Copy following script into any form and hit F5.

    [PHP]Option Explicit
    Public gConn As New Connection

    Private Sub Form_Load()
    Dim rRes As New ADODB.Recordset


    gConn.Open "Provider=SQLOL EDB;database=db name;server=ser vername;uid=use rname;pwd=xxxxx "

    Set rRes = gConn.Execute(" Select * from sysobjects order by name")

    Me.Show

    Do While Not rRes.EOF
    Print rRes(0)
    rRes.MoveNext
    Loop


    End Sub[/PHP]

    Good Luck.

    Comment

    • iburyak
      Recognized Expert Top Contributor
      • Nov 2006
      • 1016

      #3
      Don't forget to change database, server, uid and pwd to yours.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by adnan amin
        i need help how to login from VB into sql server using sql server account
        You can also create a system DSN and connect through that in VB.

        Comment

        • adnan amin
          New Member
          • Jan 2007
          • 8

          #5
          Originally posted by iburyak
          Don't forget to change database, server, uid and pwd to yours.
          friend which code u sent me.
          i hav done this already...but now i want to create a admin user and employee user of the single database...if admin enter his username and pw so he will hav all rights and if employee enter his identification so limited record will b displayed ,,,,so my question is that...how i create two accounts and from vb how to enter them

          Comment

          • iburyak
            Recognized Expert Top Contributor
            • Nov 2006
            • 1016

            #6
            In connect string you have UID and PWD so you will know who requesting records on the server.
            Create two different accounts and with different rights using Enterprise Manager.

            You can create restricted view that would be granted to users with restricted rights and revoke all rights directly to tables.
            You can use suser_sname() function on server side to check on user name that currently logged in.

            Good luck.

            Comment

            • adnan amin
              New Member
              • Jan 2007
              • 8

              #7
              thanks
              wish u all the best

              Comment

              Working...