title: host is not allowed to connect to this MySQL Server in vb.net
body: <p>hi there i am performing a unit test on my fully operational SMS application.</p>
  
  <p>i have a module with these set of codes</p>
  
  <pre><code>Imports MySql.Data.MySqlClient
  Module mdlConnect
  Public cn As New MySqlConnection
  Public mycom As New MySqlCommand
  Public myr As MySqlDataReader
  Public fail As String
  
  Function sqlconnect(ByVal strS As String, ByVal strU As String, ByVal strP As String) As Boolean
      Try
          cn.ConnectionString = "SERVER=" &amp; strS &amp; "; USER ID=" &amp; strU &amp; ";Password=" &amp; strP &amp; ""
          cn.Open()
          Return True
      Catch ex As Exception
          fail = ex.Message
          Return False
      End Try
  End Function
  
  Function command(ByVal strQ As String) As Boolean
      Try
          mycom.Connection = cn
          mycom.CommandText = strQ
          mycom.ExecuteNonQuery()
          Return True
      Catch ex As Exception
          fail = ex.Message
          Return False
      End Try
  End Function
  End Module 
  </code></pre>
  
  <p>And a database connection window with these values</p>
  
  <pre><code>Public Class frmDatabaseConnection
  'If Statement for Database Connection
  Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
      Try
          If sqlconnect(txtServer.Text, txtUsername.Text, txtPassword.Text) = True Then
              Dim query(8) As String
  
              query(0) = "Create database if not exists dbsms;"
              query(1) = "Use dbsms;"
              query(2) = "Create table if not exists tbl_administrator(SecretCode varchar(10) not null default '', Username varchar(20), Password varchar(20),Primary Key(SecretCode));"
              query(3) = "Create table if not exists tbl_students(Idno varchar(10) not null default'',Name varchar(60), Course varchar(10), YearSec varchar(20), Organization varchar(20), MobileNum varchar(15), Primary Key(Idno));"
              query(4) = "Create table if not exists tbl_user(Username varchar(20) not null default '', Password varchar(20), Name varchar(20), Position varchar(20), MobileNum varchar(15), Primary key(Username));"
              query(5) = "Create table if not exists tbl_announcement(ID int(10) not null auto_increment, Recipients varchar(40), Description varchar(500), CDate varchar(100), Sender varchar(30), AnnouncementStatus varchar(20), Primary key(ID));"
              query(6) = "Create table if not exists tbl_activity(ID int(10) not null auto_increment, Username varchar(20), Activity varchar(30),CDate varchar(50), Primary key(ID));"
              query(7) = "Create table if not exists tblgetname(ID int(10) not null auto_increment, UserName varchar(20), Primary key(ID));"
              query(8) = "Create table if not exists tbl_inbox(ID int(10) not null auto_increment, message varchar(300), received_date varchar(50), sender varchar(30), Primary key(ID));"
  
              'For statement for database and tables
              For i As Integer = 0 To 8
                  'If statement for executing all query
                  If command(query(i).ToString) Then
                      'If statement for Assuring all query are executed
                      If i &gt;= 8 Then
                          MessageBox.Show("Database Connected", "Database Connection", MessageBoxButtons.OK, MessageBoxIcon.Information)
                      End If
                      'End of If statement for Assuring all query are executed
                  Else
                      MessageBox.Show(fail)
  
                  End If
                  'End of If statement for executing all query
              Next
              'End of For statement for database and tables
  
              'Function which contains Sql Command for Selecting Administrators SecretCode
              SelectSecretCode()
  
              'If Statement for assuring SecretCode contains value
              If myr.HasRows Then
                  'If SecretCode contains value Log In form will be shown
                  Login.Show()
                  Me.Hide()
              Else
                  'If SecretCode contains no value Create Admin form will be shown to create Admin Account
                  CreateAdmin.Show()
                  Me.Hide()
              End If
              'End of If Statement for assuring SecretCode contains value
          Else
              MessageBox.Show(fail, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
              clear()
          End If
          'End of If Statement for database connection
          myr.Close()
      Catch ex As Exception
          MsgBox("Invalid use of special characters and symbols")
      End Try
  
  End Sub
  
  Public Sub clear()
      txtServer.Clear()
      txtUsername.Clear()
      txtPassword.Clear()
  End Sub
  
  Public Sub SelectSecretCode()
      mycom.Connection = cn
      mycom.CommandText = "Select SecretCode from tbl_administrator"
      myr = mycom.ExecuteReader
  End Sub
  
  Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
      If MessageBox.Show("Exit System", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
          Me.Close()
          Application.Exit()
      End If
  End Sub
  
  Private Sub frmDatabaseConnection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
  End Sub
  End Class
  </code></pre>
  
  <p>all these code go perfectly smooth when i run my system. i can establish connection to the database. i can save and retrieve data on the process further than this forms.
  but as i start to perform unit test in my system i came to an error which states as the image below.</p>
  
  <p><a href="https://i.stack.imgur.com/zW5HK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zW5HK.png" alt="test run error"></a></p>
  
  <p>it keeps on appearing on this line of code</p>
  
  <pre><code>    Public Sub SelectSecretCode()
      mycom.Connection = cn
      mycom.CommandText = "Select SecretCode from tbl_administrator"
      myr = mycom.ExecuteReader &lt;-------error
      End Sub
  </code></pre>
  
  <p>i also add this second image for further information</p>
  
  <p><a href="https://i.stack.imgur.com/yCYjr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yCYjr.png" alt="test error 2"></a></p>
  
  <p>any solutions or help is very appriciated because we are running out of time. thanks</p>