missing c# references to System.Data

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?

thanks in advance to anyone who can help me out.

In JS you’d use #import System;. I think the C# equivalent is #using?

#using System;

[edit: #imput? clearly need more sleep.]

I think you mean

@import System;

For C# it’s

using System.Data;

At the very top of the file, outside the class definitions.

-Jeremy

sorry, should have also explained that i had done that. i have included all of these:

using System;
using System.Data;
using System.Data.SqlClient;

at the start of my code, and also tried various combinations thereof.

These are the lines of code that are causing the error. Unity can’t find the System.Data namespace.

fixed :smile:

in case anyone’s interested, i found 2 solutions here: http://forum.unity3d.com/viewtopic.php?t=8432

i just included System.Data.dll in my assets folder and it works now.

Hi there,

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).

So simply don’t do it :wink:

Sunny regards,
Jashan

1 Like

that’s a good point.

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. :frowning: 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. So your reply above’s path is for iOS case?
Then how to solve in windows and android case?

Hi. Your link now says page not found.

I am also stuck this problem and plz let me know the solution.

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.

1 Like


你好!我好像也出现了跟你一样的问题,你是怎么解决的啊?能麻烦你帮我一下吗?谢谢!

1 Like

You can show this videos to connect unity 3d and sqlite and solved all dll error compile for different windows 32bit and 64bit

That link says this now:

“The requested page could not be found.”