Tom's Subject Directory & City Building Fan Site

Search a Section of this site or the Entire Site
site search by freefind

Welcome! Your IP address is; 54.162.250.227






Installed on this system:
  • Microsoft Visual Studio 2008
    Version 9.0.30729.1 SP
    Installed Edition: Standard
  • Microsoft .NET Framework 3.5
  • MySQL Connector/Net 6.2.4

Links you may need to visit:

Microsoft Express Site
Microsoft Update Site
Example databases for MySQL
MySql Connector/NET Tutorials

justhost UK banner


justhost banner


affiliate_link








Visual Basic 2008 & Mysql Version 5


An Article and Tutorial:  Connecting to MySql

Complete Source Code

Download

Imports MySql.Data.MySqlClient
Public Class frmLogin
    ' Declare and Assign values to MySql login variables
    Dim Server As String = "184.154.128.18"
    Dim DBname As String = "healers1_moose"
    Dim User As String = "healers1_tomnobl"
    Dim Password As String = "Winslow@1"
    '   Status variables
    Dim statConnect As String = "Server Status: Connected."
    Dim statFail As String = "Sever Status: Could Not Connect!"
    Dim connClosed As String = "Sever Status: Connection Closed."
    '   MySql Connection String
    '   Valid name or IP address can be "Server", "Host" & "Data Source"
    '   Valid Username can be "User", "uid" & "User id"
    Dim connStr As String = "Server=" & Server & ";Database=" & DBname & ";User id=" & User & ";pwd=" & Password & ";"

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Show()
        Connect()
    End Sub

    Public Sub Connect()
        Dim Connection As New MySqlConnection(connStr)
        Try
            Connection.Open()
            '   Connection made, change form ststus
            svrStatus.Text = statConnect
        Catch ex As MySqlException
            '   Connection not made, change status label
            svrStatus.Text = statFail
            MsgBox("Error " & ex.Number & ": Access denied" & vbCrLf & "Please try again", MsgBoxStyle.Critical)
        End Try
    End Sub

    Public Sub authenticate()
        '   MySql SELECT Syntax for retrieving user id with correct login name & password
        Dim query As String = "SELECT id FROM user WHERE name = " & "'" & TxtUsername.Text & "'" & " AND password = " & "'" & txtPassword.Text & "'"
        Dim Connection As New MySqlConnection(connStr)
        Dim cmd As New MySqlCommand(query, Connection)
        Dim reader As MySqlDataReader
        Try
            Connection.Open()
            reader = cmd.ExecuteReader()
            reader.Read()
            MsgBox("User ID: " & reader.GetString(0))
            reader.Close()
        Catch ex As MySqlException
            MsgBox(ex.Number & " - " & ex.Message)
        Finally
            Connection.Close()
            svrStatus.Text = connClosed
        End Try
    End Sub

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        authenticate()
    End Sub

    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        TxtUsername.Text = ""
        txtPassword.Text = ""
        TxtUsername.Focus()
        Connect()
    End Sub

End Class

Part I Part II Part III








Warning: mysql_connect(): Access denied for user 'tmnobles_tom'@'192.232.216.159' (using password: YES) in /home4/tmnobles/public_html/Subject_Directory/Visual_Basic/comments/config.php on line 15
Could not connect to MySQL