שתף באמצעות


[HELP] Access denied for user 'root'@localhost (Using Password: YES) MySql

Question

Tuesday, July 11, 2017 8:37 AM

hi guys..

i want to connect on my MySql in my website online

but i have error message..

my code:

 Public Class Form1
    Dim MYSQLC As New MySqlConnection
    Dim MSQLDA As New MySqlDataAdapter
    Dim DTABLE As New DataTable
    Dim BSOURC As New BindingSource

#Region "Database Information"
    Dim server As String = "localhost"
    Dim userid As String = "root"
    Dim password As String = "123456789"
    Dim database As String = "sqldb"
#End Region

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
            DTABLE.Rows.Clear()
            MYSQLC.ConnectionString = "server=" & server & ";" & "user id=" & userid & ";" & "password=" & password & ";" & "database=" & database
            Dim query As String
            query = "SELECT * FROM sqldb.info ORDER BY id"
            Dim SqlCommand As New MySqlCommand(query, MYSQLC)
            MSQLDA.SelectCommand = SqlCommand
            MSQLDA.Fill(DTABLE)
            BSOURC.DataSource = DTABLE
            DataGridView1.DataSource = BSOURC
            MSQLDA.Update(DTABLE)
            MYSQLC.Close()
        Catch myerror As MySqlException
            MessageBox.Show(myerror.Message, "ERR", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            MYSQLC.Dispose()
        End Try
End Sub
End Class

by the way this codes work 100% in appserv localhost but not work online when i need connect on my website on internet

please help me

All replies (6)

Tuesday, July 11, 2017 10:12 AM

If you are using a hosted provider then perhaps you should inquire with the provider about properly setting up the connection. Usually providers have a control panel to setup permissions to access data at different levels while the default is to refuse access to the database.

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator


Tuesday, July 11, 2017 10:51 AM

On Internet your databaseserver on our PC is not called "Local" and more of that. 

Also your connectionstring is complete wrong. 

https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/

Be aware that most persons in this forum use freeware Microsoft Database server instead of those from Oracle. 

However, first try what the IP address is of your server, using DNS you never find it if it is on a local PC.

Success
Cor


Tuesday, July 11, 2017 12:04 PM

Are you specifying the IP address in the connection string? Also, the database must be configured to accept remote connections.

https://www.connectionstrings.com/mysql/

Paul ~~~~ Microsoft MVP (Visual Basic)


Tuesday, July 11, 2017 2:22 PM

You don't access a database directly over the Internet. It would require you to open ports on the firewall to gain access to the machine that is hosting the DB, which leaves the machine and the DB exposed on the Internet to be attacked and compromised.

The DB needs to be sitting behind a Web service and your program consumes the Web service to access the protected DB.


Wednesday, July 12, 2017 2:58 AM

Hi KORG.Pa3x,

You need to install Connector/Net, which will give you a full ADO.Net provider for MySql you can use.

More detailed step, please refer to:

http://www.visual-basic-tutorials.com/Tutorials/MsCodes/code8.htm

Best Regards,

Cherry

Note: This response contains a reference to a third party World Wide Website. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any
software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


Wednesday, July 19, 2017 7:23 AM

Hi KORG.Pa3x,

Please remember to close your thread by marking helpful post as answer, it is very beneficial to other community members who face the same issue.

Thanks for your understanding.

Best Regards,

Cherry

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.