0

I'm trying to connect to a database but it doesn't work...

Code:

        Dim conn As MysqlConnection

    conn = New Mysqlconnection()
    conn.ConnectionString = "server=http://www.*****.net/phpMyAdmin; user id=*****; password=****; database=login"

    Try
        conn.Open()
    Catch myerror As MySqlException
        MsgBox("Error connecting to database!")
    End Try

it alsways says Error connecting to database!

what's the problem??

1
  • 1
    Try conn.Open() Catch myerror As MySqlException MsgBox(myerror.message) End Try This will give you more detailed exception information. Commented Apr 25, 2011 at 13:27

3 Answers 3

3

You cannot use http://www.*****.net/phpMyAdmin for your server name. it should be just your domain name(hostname) mydomain.com or IP address 192.168.0.10

it should look as follow:

Dim conn As MySqlConnection = New MySqlConnection
conn.ConnectionString = "Host=192.168.0.10;user=root;password=root"
conn.Open()
Sign up to request clarification or add additional context in comments.

1 Comment

Even if i do this 'conn.ConnectionString = "Host=***.*.**.***; user id=*******; password=******"' it doesn't work..
2

First ensure that MySQL Connector/NET is installed. Check all credentials are correct. Then try this snippet.

    Imports MySql.Data.MySqlClient
Public Class MySQLConnect
    Private db_con As New MySqlConnection
    Private Sub connect()
        Dim dbname As String = "DBNAME"
        Dim dbhost As String = "localhost"
        Dim user As String = "root"
        Dim pass As String = "DBPASSWORD"


        If Not db_con Is Nothing Then db_con.Close()
        db_con.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", dbhost, user, pass, dbname)

        Try
            db_con.Open()
        Catch ex As MySqlException
            MsgBox("Database Error:[" & ex.Message & "]")
        End Try
    End Sub
End Class

Try this link, it's very straight forward.

Comments

-2
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class LoginForm1
    Dim mysqlconnection As MySqlConnection

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        mysqlconnection = New MySqlConnection
        mysqlconnection.ConnectionString = "server=servername.com;port=portnum;user id=username ;pwd=password;database=databasename"
        'mysqlconnection.Open()
        Try
            mysqlconnection.Open()
        Catch myerror As MySqlException
            MsgBox("Error connecting to database!")
            Exit Sub
        End Try
        MsgBox("connected to database!")
    End Sub

1 Comment

Welcome to StackOverflow. You have some formatting problems with your code. It's also usually desirable to add a little bit of text explaining your solution. You can edit your post to make these changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.