Results 1 to 14 of 14

Thread: MySQL Connection Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    31

    MySQL Connection Problem

    Hello Guys,

    Looks like this is an active forum, looking forward to get some help .

    Alright, so here is my thing, I'm starting to learn manipulating data in database. But before that I needed to connect to my database which is SQLYog (MySQL Base). So here is a snapshot of my connection string.

    Code:
    Private dbConnection As OdbcConnection
    
    Private Sub TestConnection()
            dbConnection = New OdbcConnection
    
            dbConnection.ConnectionString = ""
            dbConnection.ConnectionString &= "DRIVER = {MySQL ODBC 5.1 Driver}; "
            dbConnection.ConnectionString &= "SERVER = localhost; "
            dbConnection.ConnectionString &= "USER = root; "
            dbConnection.ConnectionString &= "PASSWORD = root; "
            dbConnection.ConnectionString &= "OPTION = 3;"
    
            Try
                dbConnection.Open()
                MessageBox.Show("Successfully connected to database.")
                dbConnection.Close()
            Catch ex As Exception
                MessageBox.Show("Unable to connect to database.")
            Finally
                dbConnection.Dispose()
            End Try
    End Sub
    The only thing is, this error keeps on showing:

    Code:
    "Datasource not found and default driver specified"
    Could anyone point me out why this keep happening.
    Any help would be appreciated. Thank you

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,712

    Re: MySQL Connection Problem

    It looks like SQLYog is simply a front end GUI for a MYSQL backend and has nothing to do with connection to a MySQL sever.

    In order to connect to a MYSQL server from .net, you need the MySQL .NET Connector which can be found here . T Once you have installed the connector, you will be able to add the MySql.Data as a reference to your project. You will then need to use the methods in that namespace to connect to the server.


    Code:
      Dim server As String = mySettings.dbServer
            Dim user As String = mySettings.dbUser
            Dim pw As String = mySettings.dbPassword
            Dim db As String = mySettings.dbName
    
            Dim _connectionString As String = String.Format("Server={0};Uid={1};Pwd={2};Database={3}", server, user, pw, db)
    
            conn = New MySql.Data.MySqlClient.MySqlConnection(_connectionString)
    Last edited by kebo; Jan 30th, 2015 at 02:48 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    31

    Re: MySQL Connection Problem

    Thank you for your reply, Unfortunately it didn't work. Do you think there something wrong in my code?

    Code:
        Private Sub TestConnection()
            Dim server As String = "localhost"
            Dim user As String = "root"
            Dim pw As String = "root"
            Dim db As String = "DBase."
    
            Dim _connectionString As String = String.Format("Server={0};  Uid={1}; Pwd={2}; Database={3}", server, user, pw, db)
            mySettings = New MySqlClient.MySqlConnection(_connectionString)
    
            Try
                mySettings.Open()
                MessageBox.Show("Successfully connected to database.")
                mySettings.Close()
            Catch ex As Exception
                MessageBox.Show("Unable to connect to database." & ex.Message)
            Finally
                mySettings.Dispose()
            End Try
        End Sub

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,972

    Re: MySQL Connection Problem

    "it didn't work" isn't very helpful... that could mean a number of things. What was the exception message?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,712

    Re: MySQL Connection Problem

    Quote Originally Posted by techgnome View Post
    "it didn't work" isn't very helpful... that could mean a number of things. What was the exception message?

    -tg
    this ^^^

    However, your code works fine when I use my connection parameters. I am going to guess you are dealing with a configuration issue. Either your connection parameters aren't correct, and/or the database/user is not configured correctly.
    kevin
    Last edited by kebo; Jan 31st, 2015 at 11:46 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: MySQL Connection Problem

    Code:
    Dim db As String = "DBase."
    Just a guess, but it seems odd to have a period at the end of the database name.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    31

    Re: MySQL Connection Problem

    Same error message was given to me. How should I know that the parameters that I specified is for SQLYog Database?

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,972

    Re: MySQL Connection Problem

    There is no such thing as a SQLYog database. SQLYog is a GUI front end to MySQL. So the database is a MySQL database. But from inside of SQLYog you should be able to see the connection settings it is using to connect to the database.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: MySQL Connection Problem

    I'm guessing the problem is that you are not telling the connection which database to use. In your first question, you state that the error message was "Datasource not found and default driver specified" and in the code generating that error, you don't list the DataSource (eg the name of the database). Then when you tried to use kebo's code, you use "DBase." as the name of the database / datasource, but I agree with TnTinMN that that doesn't sound like a database name either. Note that when I'm saying the database name, I mean the name of the actual database, not the database management system (which in your case would be MySQL; as others have pointed out, SQLYog is just a GUI front-end for MySQL databases). The DBMS / database server may be running many different databases, so the connection needs to know not only how to connect with the server, but also which database to interact with.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    31

    Re: MySQL Connection Problem

    That would be the case, I don't know what database should I put into the parameter.

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,972

    Re: MySQL Connection Problem

    It would be the name of the database you want to connect to.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    467

    Re: MySQL Connection Problem

    When connecting to a MySQL database you also need a port. The default I believe is 3306 but when the MySQL server is started, it can be started on virtually any port. If you connect to a MySQL database with SQLYog, it will ask for a port, in addition to the server, userid and password. When entered correctly, it will show you the databases that exist in that server instance. Then you can use that information to build your connection string in VB.

    Note, if the server is not running, SQLYog will not start it. It must be running already.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    31

    Re: MySQL Connection Problem

    Alright, now I'm having a tough time figuring out different connection strings.
    Could anyone help me out how to easily configure connection strings of different database (SQL Server, MYSQL) in different GUIs.

    I found this guy (www.connectionstring.com) for reference yet dunno how to supply the correct parameters.

  14. #14
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    467

    Re: MySQL Connection Problem

    Try http://www.connectionstrings.com/mysql/ instead. Note the s on connectionstrings. I believe it's where I originally built my setup from about 6 or 7 years ago.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width