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.
 
If I remember correctly, recent versions of the MySQL .NET components have separated the runtime components from the design time tools. Have you installed both on your system?
 
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
 
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.
 
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.
 
Back
Top Bottom