Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15549

Simple DB connection question

$
0
0
Hi,

I am trying to connect to a sql DB my test connection works fine from the TOOLS connect to DATASOURCE but i cannot access the DB.

Code:

    Private Sub btnlogon_Click(sender As Object, e As EventArgs) Handles btnlogon.Click
        If txtpassword.Text = "" Or txtusername.Text = "" Then
            MessageBox.Show("Please enter a Username or Password...", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else

            Dim Sqlcon As SqlConnection = New SqlConnection("Data Source=PHONE-SYSTEM\RFID;Initial Catalog=RFID;Persist Security Info=True;User ID=sa;Password=******")
            Dim SQLcmd As SqlCommand
            Dim QueryOpen As String = "select * from [AdminAccess] Where userid='" & txtusername.Text & "' and password = '" & txtpassword.Text & "'"

            Try
                SQLcmd = New SqlCommand(QueryOpen, Sqlcon)
                Sqlcon.Open()
                Dim reader As SqlDataReader = SQLcmd.ExecuteReader()
                If reader.Read() Then
                    Form3.Show()
                    txtusername.Text = ""
                    txtpassword.Text = ""
                    Me.Close()
                Else
                    MessageBox.Show("Username and password do not match...", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    txtusername.Text = ""
                    txtpassword.Text = ""
                    txtusername.Focus()
                End If
            Catch
                MessageBox.Show("Failed to connect to database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        End If

    End Sub

I just get the failed to connect to database error anyone got any idea's i just cannot get me head around it.

Cheers James

Viewing all articles
Browse latest Browse all 15549

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>