Odd behavior when attempting SQL interaction

Hi all,
I’m fiddling with SQL and I’ve come across an interesting situation. If I use the System.Data.dll found in (I’m on WIndows) Unity\Editor\Data\MonoBleedingEdge\lib\mono\unity\ then the connection succeeds, but IL errors are thrown when I try to execute a query. (InvalidProgramException: Invalid IL code in System.Data.Common.DbConnection:System.Data.IDbConnection.CreateCommand (): IL_0000: ret)
However, if I use the System.Data.dll found in Unity\Editor\Data\Mono\lib\mono\2.0 then I can’t even connect (“System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.”) even using the same connection string.

If there’s a different dll that I should be using for SQL interaction, or what, but it’s becoming quite frustrating. So much so, that I’m considering just abandoning simplicity and figuring out PHP (which I don’t want to do because it’s an unnecessary extra step and extra setup)

Any pointers on what I might be doing wrong would be appreciated.

Edit: I found a version of the MySql.data.dll that Unity would recognize, since the one I had was targeted for a higher .NET framework. It succeeds where System.Data.dll failed.

Yes, you are correct that you need to use the MySQL version of the dll.

It appears that MySql.Data.dll has reliance on System.Data.dll and I can’t for the life of me get both Unity and Visual Studios to retain the reference.

using php implies that you have a server where this sql database is located…

is this a client that connects to a server, and you have your db just sitting wide open on the internet?

…

I’d avoid doing that. It’s a huge security hole.

Rather instead create some webservice on your server (php could work, .net WCF web service could as well, node.js, or any number of many other options), and create a simple CRUD interface between your client and the database which you can then use for validation/authentication.

Added benefit is that growth of your database (load balancing, maintenance, and ottherwise replacement of) could be kept independent of your clients. The CRUD interface stays the same, the backend can grow as needed.

Good heavens, no. I know better than to allow clients to access the db. The setup will be: Client communicates with the host server, which will clean and interpret anything received from the client or sent to it (to protect against injections and keep clients from even knowing the address of the db) who then connects and interact with the database.
So, Client → Dedicated server → SQL database

Is there a need for the server to be made with Unity?

Besides that I don’t know how to make a server with anything else, and that C# is the only programming language that I know at any level of competency, maybe. The game server will also be handling game data, and that’s probably easiest to deal with in Unity. Plus, the server will be running on Linux, and the ease of building for Linux that comes with Unity makes matters simpler.

Well, mono, which is the runtime Unity uses for crossplatformability, you can develop directly in it.

And you can have the latest features in the most recent version of it if you don’t use Unity.

At the moment I currently develop with mono on debian for the raspberry pi, that communicates with a linux server also running mono. I personally use WCF messaging for it myself.

Interesting. Certainly something I’ll need to look into - Heck, it may not even be all that far from what I’m doing now, with Unity just packing it all into an executable - but I feel that it might be a bit outside my comfort zone.
I’m primarily concerned about getting things to work. Getting them to work well comes later.

Still, it’s annoying that the reference in Visual Studios keep breaking. I have to remove the reference and re-add it every time I open VS.

Unity likes to handle the references to libraries for you. If you put the dll’s into the Assets folder (or subfolder of that), it’ll maintain them for you.

That’s what the internet says, but it isn’t. I’ve got the System.Data.dll in the Assets folder, not even in any subfolders. But Every time I open VS, I have to re-add the reference. It otherwise works fine.

I still can’t get VS to retain the reference. I’ve tried changing the API compatibility level, I’ve tried putting the dll in different folders, re-importing just the dll, re-importing everything, trying in a new project, using older versions of the dll, using native versions.
Nothing is working.
Maybe there’s something in 5.5.1f1 that won’t allow MySQL.Data to reference System.Data? Maybe there’s a conflict somewhere? I don’t know, and it’s really frustrating.

It looks like the System.Data.dll from the path Editor\Data\MonoBleedingEdge\lib\mono\2.0-api will maintain reference in VS. I don’t know why it doesn’t work with any other dll, but yeah. For anyone else fiddling with MySQL, that’s the path you need to get the dll from.

What are you using as your connection string?

All I keep getting told is the following:
• 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)

Also what version of MySQL.Data are you using?
This is my connection string: “server=localhost;uid=USER;pwd=MYPASSWORD;database=MYDATABASE;” is it the same structure as yours?
My version is v6.9.8.0 which I got from the MySQL Site.

Thanks

Paul

I’m apparently using 6.2.4.0, don’t recall where I got it from. What method is causing the exception? I was getting a similar exception, but at database.Open() and I resolved it by changing the SQL database collation. I could have sworn I set it to Utf16_general_ci, but that’s not what I’m seeing.
Anywho, I suggest you fiddle with your collation settings.