Search code examples
c#mysql.netinstallationmysql.data

Installed Application Fails To Load MySQL.Data.DLL?


I have an application that runs perfectly on my system (both in the IDE, and installed), but fails completely when installed on any other system.

I moved an abridged version of the source code over to see if I could figure out what the issue was, and much to my boundless fury, I discovered the error occurred when the program attempted to reference a class contained in another library which made use of the MySQL.Data.DLL file...

[Insert endless string of curses, swears, and otherwise R-rated language here].

Why? WHY? WHY?! WHY?!?! SERIOUSY - WHAT THE HELL?!


Solution

  • When you use MySql in your applications and install on client machines, it will search MySql.Data.dll in client machine and goes to the path

    C:\Program Files (x86)\MySQL\MySQL Connector Net X.X.X\Assemblies\ (assuming you have installed MySql connector in C drive)

    Exploring Assemblies folder you would see this MySql.Data.dll check this file's version and similarly check your's MySql.Data.dll they must be same.

    The average layman user won't have the MySQL connector installed. What am I supposed to do when this program is released for general circulation and John Q. User can't run it because they don't have this obscure... thing installed?

    Your application must Package all of its per-requisites with it, so when client install it, per-requisites should also install with your software. Lets suppose I developed an application with MySql connector 6.9.6.0.

    DO the following things

    1. Package MySql Connector with your software build
    2. specify MySql Connector version in App.Config file.

       <system.data>
          <DbProviderFactories>
              <clear/>
              <remove invariant="MySql.Data.MySqlClient"/>
              <add name="MySql.Data.MySqlClient" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=6.9.6.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d"/>
          </DbProviderFactories>
      </system.data>
      

    Now client machine will specifically search for the mentioned version in app.config.

    By the way these two points are optional, if you don't do these then you have to take care of each and everything, as your are doing now.