开发者

C# MySql Connector/Net issues

Currently running Mono. I loaded MySQL and installed connector/net in my gac folder located in /usr/lib/mono/gac. The problem is that everytime I try to run it using a simple connection test, I get the following error:

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: The following assembly referenced from /home/holland/Code/csharp/test/Test/bin/Debug/Test.exe could not be loaded:
     Assembly:   MySql.Data    (assemblyref_index=1)
     Version:    6.4.4.0
     Pu开发者_高级运维blic Key: c5687fc88969c44d
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/home/holland/Code/csharp/test/Test/bin/Debug/).


** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Could not load file or assembly 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Missing method .ctor in assembly /home/holland/Code/csharp/test/Test/bin/Debug/Test.exe, type MySql.Data.MySqlClient.MySqlConnection

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Could not load file or assembly 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Missing method .ctor in assembly /home/holland/Code/csharp/test/Test/bin/Debug/Test.exe, type MySql.Data.MySqlClient.MySqlConnection

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.
File name: 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'
  at Test.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 

It should be an assembly file if I recall correctly

Here's my code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using MySql.Data.MySqlClient;

namespace Test
{
    public class Database
    {
        public Database()
        {

        }

        public static IDbConnection MainConnect()
        {
            string connectionInfo = 
            "Server=localhost;"+
            "Database=ecom_main;"+
            "User ID=root;"+
            "Password=xxxxxxx"+
            "Pooling=false;";

            return new MySqlConnection(connectionInfo);
        }
using System;
using System.Data;
using MySql.Data.MySqlClient;

namespace Test
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            IDbConnection dbMain = Database.MainConnect();

            Console.WriteLine(dbMain);
        }
    }
}


I had the same problem and I solved it following this steps:

  1. Make a copy case sesitive of the dll:
#cp mysql.data.dll MySql.Data.dll
  1. Install the connector
    #gacutil -i -package 2.0 MySql.Data.dll
    This installs in the GAC and also adds a symlink in /usr/lib/mono/2.0
  2. If the assembly does not appear in monodevelop, then you can add a reference to the dll in the project to /usr/lib/mono/2.0

+info: http://dev.mysql.com/doc/refman/5.1/en/connector-net-installation-unix.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜