hi, i’m having a problem getting some C# code to work. it’s telling me that i am missing the necessary reference for System.Data
i opened the unity.app package and can see the System.Data.dll file in there, so I can’t figure out what’s going wrong. unless it’s because i’m using Unity Indie or something…
any ideas?
alternatively, is there another namespace i can use to write code to connect to a MySQL database?
Assets/Network Assets/Scripts/ServerDatabaseIO.cs(4) error: The type or namespace name `System.Data' could not be found. Are you missing a using directive or an assembly reference?
Assets/Network Assets/Scripts/ServerDatabaseIO.cs(4) error: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
just a quick note to save anybody doing this potential bad-ass headaches:
Make sure you use System.Data.dll from the Unity distribution. You’ll find this in the path
If you have Mono installed on your machine, you might also find System.Data.dll in an alternative path:
… I just spent quite a few hours spread over a couple of days finding out why Unity frequently crashed after I closed it, and my game server (which uses the database) crashed frequently when I closed it.
That was the reason (using a probably more recent System.Data.dll instead of the one coming with Unity).
i took the System.Data.dll file from the Unity package, but the System.Data.SqlClient.dll file came from some random place on the internet which i don’t remember. i haven’t had any problems at all with running it in the Unity editor, though when I build my server file it no longer wants to connect to the MySQL database on localhost. this means that to test, i have to build the client and connect to a server running inside the Unity editor, which is starting to get kinda annoying.
i’m thinking this is more of a system security problem than a dll related issue though…
Do you have any DLLs in your project root folder? I.e. something like
Project/SomeDll.dll
Project/Assets/SomeDll.dll
with my Unity installation, I’ve recently had a problem with that kind of set up that also caused something to work inside the editor, and not work in the standalone build. In my case, removing Project/SomeDll.dll fixed the problem.
Hi, it’s actually not my link – it looks like the URLs weren’t fully remapped when Unity moved over to the new forum a while ago.
Also, that post is from 6 years ago! Does this issue still exist? I stopped using MySQL in my projects and moved over to SQLite. Not sure what difference that makes.
Did you try including System.Data.dll in your Assets folder as mentioned above?
I found the solution for adding System.Data.dll (I’m also using UnityVS):
You can find the solution by navigating to:
Copy the ProjectFileHook.cs to Assets\Editor folder and copy System.Data.dll file from
C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\unity\System.Data.dll
to your Assets folder (not to plugins, but directly to Assets).
If you want to put your DLL file in another location within Assets folder, you must edit the path in line 56 of ProjectFileHook.cs:
RemoveFileFromProject(document, @“Assets\System.Data.dll”);
to the path where your file lies.