Difficulty connecting to MySQL

I’m running the latest Unity Free in on a Mac, OS 10.6.6. I’m following the instructions in this post:

Reading database and/or spreadsheets.

The CS script I’m trying to use is here:

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

public class DatabaseConnectionScript : MonoBehaviour {

	
	// Update is called once per frame
	void Update () {
	
	}
	    // Global variables
    private static IDbConnection dbConnection;
    
    // Initialisation
    public void Start() {
        openSqlConnection();
        Debug.Log("Database Script run.");
   }
    
    // On quit
    public void OnApplicationQuit() {
        closeSqlConnection();
    }
    
    // Connect to database
    private static void openSqlConnection() {
        string connectionString = "Server=localhost;" +
            "Database=Test01;" +
            "User ID=unity;" +
            "Password=password;" +
            "Pooling=false";
        dbConnection = new MySqlConnection(connectionString);
        dbConnection.Open();
        Debug.Log("Connected to database.");
    }
    
    // Disconnect from database
    private static void closeSqlConnection() {
        dbConnection.Close();
        dbConnection = null;
        Debug.Log("Disconnected from database.");
    }

    // MySQL Query
    public static void doQuery(string sqlQuery) {
        IDbCommand dbCommand = dbConnection.CreateCommand();
        dbCommand.CommandText = sqlQuery;
        IDataReader reader = dbCommand.ExecuteReader();
        reader.Close();
        reader = null;
        dbCommand.Dispose();
        dbCommand = null;
    }

}

I copied the two DLL files attached to the referenced post into the Assets folder of the project directory I’m working on.

When I try to run within the Unity environment just to see whether the code thus far is doing okay, I get these internal compiler errors:

I verified the subject MySQL database and user information exist on my Mac and I can log into the database normally.

Does anyone know what’s going wrong here?

Many thanks in advance!

The error message is not very informative but if you go to the player settings (menu: Edit > Project Settings > Player) and set the API compatibility level to 2.0, rather than 2.0 Subset then it should fix the problem. You may need to re-save the database script to make Unity register the change.

The System.Drawing library referenced in the error message is not applicable in Unity and is therefore only a placeholder implementation for the sake of other libraries that depend on it. When you have API compatibility set to Subset, Unity leaves out these “useless” libraries and other little-used ones as a way to save memory in the final build.

You’re the man! At first I thought it wasn’t going to work, but then I realized I hadn’t re-saved the script. Viola, I have connection.

Thank you!

A follow-up question: I intend for the final build to be deployed as a web app. Are there issues in that case with the app having access to the DLLs?

Wow… so I got exactly the same error as this guy…
I followed Andeee’s suggestion and I ended up getting nowhere…
So I did his advice backwards and ended up with the same error message twice…
i followed the advice again and lo and behold, now I only get the same error once again :stuck_out_tongue:

So, erm… how do I make that error go away?
Please, help…
Thanks