Beginners Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Elias Alhanatis
    New Member
    • Aug 2007
    • 56

    Beginners Question

    Hello everybody!

    Can anyone please help me with the connection to an SQL Server? I use the
    following code:

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim LibraryDB As New SqlClient.SqlConnection( _
                "Data Source=ELIAS-NEWPC\SQLEXPRESS;" & _
                "Initial Catalog=Library;User ID='Elias-NewPc\Elias';Integrated Security=true")
            LibraryDB.Open()
            MessageBox.Show("Connection Established!")
        End Sub
    End Class
    .. and i get a "Login failed for user ''. The user is not associated with a trusted SQL Server connection.".
    Is there a major mistake in the code , or i have to configure again the SQL Server?

    Thank you in advance!

    Elias
  • nazimsal
    New Member
    • Nov 2008
    • 5

    #2
    Public Class Form1

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim LibraryDB As New SqlClient.SqlCo nnection( _
    "Data Source=ELIAS-NEWPC\SQLEXPRES S;Initial Ctalog=Library; User ID="Elias-NewPc\Elias";In tegrated Security=true")
    LibraryDB.Open( )
    MessageBox.Show ("Connection Established!")
    End Sub
    End Class

    Comment

    • Elias Alhanatis
      New Member
      • Aug 2007
      • 56

      #3
      Hi!

      I am sorry but i cannot find any difference in the code.
      Is there something i'm missing?

      Comment

      • rpicilli
        New Member
        • Aug 2008
        • 77

        #4
        Hi there!


        "Data Source=ELIAS-NEWPC\SQLEXPRES S;" & _
        "Initial Catalog=Library ;User ID='Elias-NewPc\Elias';In tegrated Security=true")

        First, in your code try to write in only 1 line. After this line is tested you can split as many as you need.

        When you use the Integrated Security=True you don't need to put a User ID. This parameter (Integrated Security) means that the user that starts the service of SQL Sever will do the job.

        In the following line I show you how to make a connection with fake names.

        Code:
        Data Source=SQLServerPCName;Initial Catalog=MyDBName;Integrated Security=True
        That is all you need to connect to the database MyDBName in the SQLServerPCName PC.

        Try this and let me know if works for you.

        RPicilli

        Comment

        • Elias Alhanatis
          New Member
          • Aug 2007
          • 56

          #5
          Hello there!!

          Thank you so much!!!
          It worked!!!! I will also like to thank you for the advise and the comments
          which i am sure going to help me in the future!!

          Thanks again!!!!

          Elias

          Comment

          • rpicilli
            New Member
            • Aug 2008
            • 77

            #6
            You're welcome

            Rpicilli

            Comment

            Working...