Im working on this application that will transfer data from the database to another application. But I'm trying to work with a database.
I need to connect any database (Oracle, SQL, etc.) to the application, because my user database uses different databases.
I followed the tutorial http://www.splinter.com.au/using-generic-database-providers-with-c/ and I had problems connecting my MySQL test database to it.
Here is my sample code:
static void Main(string[] args)
{
string connection = "SERVER=localhost;UID=root;PASSWORD=toor";
string provider = "MySql.Data.MySqlClient";
using (DbConnection conn = (DbConnection)Activator.CreateInstance(Type.GetType(provider), connection))
{
conn.Open();
string sql = "SHOW DATABASES";
using(DbCommand comm = conn.CreateCommand())
{
comm.CommandText = sql;
using(DbDataReader reader = comm.ExecuteReader())
{
while(reader.Read())
{
string owner = reader.GetString(0);
Console.WriteLine("{0}", owner);
}
}
}
}
Console.ReadLine();
}
, , ArgumentNullException, , null. , . , MySQL. , ? , ?
, , .