how to connect mysql?

vppproj

New member
Joined
Dec 14, 2014
Messages
1
Programming Experience
Beginner
visual studio2010
I have installed my-sql-net-6.9.5, and mysql work bench,after that i created front end using c# webform in .net and tried to connect to database in visual studio through tools->connect to database->choose datasource, here it is not showing mysql database option.Please help to resolve this.
Thank you.
 

mdkusz

New member
Joined
May 25, 2016
Messages
2
Programming Experience
10+
Try using common DbConnection

Hi,

You can try this:

C#:
using System.Data;
using System.Data.Common;


...

                DbProviderFactory fact = DbProviderFactories.GetFactory("MySql.Data.MySqlClient");
                using (DbConnection con = fact.CreateConnection())
                {
                    con.ConnectionString = sb;
                    con.Open();

                   // use the connection

                }
The only problem is that you must use the common database objets instead of those on the MySql connector directly (i.e. DbCommand instead of MySqlCommand)

Regards
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,150
Location
Sydney, Australia
Programming Experience
10+
Hi,

You can try this:

C#:
using System.Data;
using System.Data.Common;


...

                DbProviderFactory fact = DbProviderFactories.GetFactory("MySql.Data.MySqlClient");
                using (DbConnection con = fact.CreateConnection())
                {
                    con.ConnectionString = sb;
                    con.Open();

                   // use the connection

                }
The only problem is that you must use the common database objets instead of those on the MySql connector directly (i.e. DbCommand instead of MySqlCommand)

Regards
Personally, I don't see the point in doing that unless you want to be able to change providers without changing the code.
 

mdkusz

New member
Joined
May 25, 2016
Messages
2
Programming Experience
10+
Personally, I don't see the point in doing that unless you want to be able to change providers without changing the code.
The point is that, using this method, you don't have to worry with the versi?n of the MySql connector, as you don't need to link it to the application as a reference.
 
Top Bottom