• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

trying to connect to MySQL with CreateConnection

I'm trying to connect to a MySQL database using System.Data.Common.  I'm need some help trying to figure out the connection string.  I've changed some of the connection infromation but basically this is what I have so far.  I'm planning on distributing this so I'm thinking that OleDB might be the best way given that I won't have to worry about distributing an MySQL driver.  I'm currently working in VB 2005.



factory = System.Data.Common.DbProviderFactories.GetFactory("System.Data.oledb")
        cnPTracker = factory.CreateConnection
        cnPTracker.ConnectionString = "Provider=****; " _
                                        & "Data Source=****;"" )" _
                                        & "Initial Catalog=PTracker;Uid=****;Pwd=****;" _
                                        & "trusted_connection=true;encrypt=true; " _
                                        & "trustservercertificate=true;"

Open in new window

0
PeterTrefren
Asked:
PeterTrefren
  • 4
  • 3
1 Solution
 
PeterTrefrenAuthor Commented:
I think what I need to have is the correct provider information.
0
 
marirajuCommented:
Hi there,

I think you can import the namespace, which uses the OLEDB and use the following statements to connect to the database.

conn = New MySqlConnection()
  conn.ConnectionString = "server=servername;user id=username;password="";"database=in_out"
conn.open()

OR

Dim connectionString As String = "Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;"

Please replace the drivername in place of "MySQL"

PS: Assuming that you have installed working MySQL server

Bye for now

Cheers
0
 
marirajuCommented:
Yes, you need the correct provider information,

Second thing, is reference and import the provider namespace
After that you should be ready to go with the above commands, which is much faster and easily accessible

Bye for now

Cheers
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
marirajuCommented:
Hi again
The starting syntax would be

Dim Con As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=..............

0
 
PeterTrefrenAuthor Commented:
The issue is the GetFactory statement is not taking the parameter 'MySQL.Data.MySQLClient'.  I can connect though the MySQL objects and can connect using the GetFactory against a SQL Server database.  However I'm not able to connect using GetFactory against a MySQL database.  
0
 
PeterTrefrenAuthor Commented:
Adding the following entry into my app.config file under system.data solved the problem.  This information is specific to the version 6.2.2.0 connector.
    <DbProviderFactories>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>

Open in new window

0
 
PeterTrefrenAuthor Commented:
I was able to connect when I updated the system.data of my app.config with this information.  This information is specific to the MySQL connector version 6.2.2.0.
    <DbProviderFactories>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>

Open in new window

0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now