I am writing a dedicated server that runs on Linux that needs to access a MySQL Database on the same machine.
I have downloaded MySQL.Data (loads of different versions) for up to .NET 3.5, which Unity accepts fine and I am able to reference it in Visual Studio fine.
Now when I add in the connection string in the code it fails with the following Error: • KeyNotFoundException: The given key was not present in the dictionary. • System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150) • MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_Database () • MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString (System.String value) • Server.Start () (at Assets/Scripts/Server.cs:47)
I am using the following connection string: “server=localhost;uid=USER;pwd=MYPASSWORD;database=MYDATABASE;”
I am like pulling my hair out due to the key names do exist due to I check in the MySQL.Data source code.
Has anyone managed to get MySQL Connections working in Unity, if so what version are you using and what connection string are you using.
Why don’t you simply use the provided classes from Unity? It might also be better to use external php files to connect to your database as php files can’t be viewed by other persons and your connection data is save. you simply need to use the php file as parameter and wait for the results, pretty simply.
@SlyRipper Sorry if I sounded harsh in my last reply but I have been up for the last 38 hours trying to get this thing working.
And having the dedicated server for a FPS that’s already using NetworkTransport then also use WebRequests to call a PHP page via an Apache webpage just for the MySQL Queries isn’t a good route to take.
Now if it was a Turn Based Game it “might” or been ok.
I have now resolved the issue, it was down to something wrong with System.Data.
I used the version found here: \Editor\Data\Mono\lib\mono\unity\System.Data.dll and it works fine on Windows and Linux.
Well, I’m using WebRequest for my queries and never had any serious problems, but I might try some more ways and check for performance issues, but usually php is pretty fast in processing queries, and if you gather them async in unity there should be less problems At least I’m using them with lazy loading and had no problems with it so far ^^