MySQL Connector/Net

View: New views
1 Messages — Rating Filter:   Alert me  

MySQL Connector/Net

by Crypton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

I have some trouble to get MySQL work in Mono. I use Ubunut as os.

I have downloaded the connector and copied the mysql.data.dll into the gac-folder.

But when I try to compile this code:

 using System;
 using System.Data;
 using MySql.Data.MySqlClient;
 
 public class Test
 {
    public static void Main(string[] args)
    {
       string connectionString =
          "Server=localhost;" +
          "Database=test;" +
          "User ID=myuserid;" +
          "Password=mypassword;" +
          "Pooling=false";
       IDbConnection dbcon;
       dbcon = new MySqlConnection(connectionString);
       dbcon.Open();
       IDbCommand dbcmd = dbcon.CreateCommand();
       // requires a table to be created named employee
       // with columns firstname and lastname
       // such as,
       //        CREATE TABLE employee (
       //           firstname varchar(32),
       //           lastname varchar(32));
       string sql =
           "SELECT firstname, lastname " +
           "FROM employee";
       dbcmd.CommandText = sql;
       IDataReader reader = dbcmd.ExecuteReader();
       while(reader.Read()) {
            string FirstName = (string) reader["firstname"];
            string LastName = (string) reader["lastname"];
            Console.WriteLine("Name: " +
                  FirstName + " " + LastName);
       }
       // clean up
       reader.Close();
       reader = null;
       dbcmd.Dispose();
       dbcmd = null;
       dbcon.Close();
       dbcon = null;
    }
 }


This messages appears(In the Mono IDE):
[Task:File=/home/bryan/Skrivbord/Testexample.cs, Line=2, Column=15, Type=Error, Priority=Normal, Description=The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?(CS0234)]

[Task:File=/home/bryan/Skrivbord/Testexample.cs, Line=3, Column=8, Type=Error, Priority=Normal, Description=The type or namespace name `MySql' could not be found. Are you missing a using directive or an assembly reference?(CS0246)]

When I try to compile the file with this line:
gmcs -r:System.dll -r:System.Data.dll -r:MySql.Data.dll /home/bryan/Skrivbord/Testexample.cs

This message appears:
gmcs -r:System.dll -r:System.Data.dll -r:MySql.Data.dll /home/bryan/Skrivbord/Testexample.cs

Can someone help me?