Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

missing c# references to System.Data

Discussion in 'Scripting' started by SixTimesNothing, Jun 14, 2008.

  1. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    161
    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?

    Code (csharp):
    1. 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?
    Code (csharp):
    1. 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.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,837
    In JS you'd use #import System;. I think the C# equivalent is #using?
    Code (csharp):
    1.  
    2. #using System;
    3.  
    [edit: #imput? clearly need more sleep.]
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I think you mean
    Code (csharp):
    1. @import System;
    For C# it's
    Code (csharp):
    1. using System.Data;
    At the very top of the file, outside the class definitions.

    -Jeremy
     
  4. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    161
    sorry, should have also explained that i had done that. i have included all of these:
    Code (csharp):
    1. using System;
    2. using System.Data;
    3. 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.
     
  5. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    161
  6. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,105
    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 ;-)

    Sunny regards,
    Jashan
     
    Nanity likes this.
  7. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    161
    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. :( 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...
     
  8. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,105
    Do you have any DLLs in your project root folder? I.e. something like

    Code (csharp):
    1.  
    2. Project/SomeDll.dll
    3. Project/Assets/SomeDll.dll
    4.  
    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.
     
  9. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    1,825
    Hi. So your reply above's path is for iOS case?
    Then how to solve in windows and android case?
     
  10. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    1,825
    Hi. Your link now says page not found.

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

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    161
    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?
     
  12. k0mbain

    k0mbain

    Joined:
    Nov 1, 2012
    Posts:
    22
    I found the solution for adding System.Data.dll (I'm also using UnityVS):
    You can find the solution by navigating to:

    https://connect.microsoft.com/Visua...013-tools-for-unity-system-data-bad-reference

    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.
     
    weuppiboy9 likes this.
  13. xiaozengxy

    xiaozengxy

    Joined:
    Dec 7, 2015
    Posts:
    1

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

    walidabazo

    Joined:
    Jul 8, 2017
    Posts:
    16
    You can show this videos to connect unity 3d and sqlite and solved all dll error compile for different windows 32bit and 64bit

     
  15. Shiasu-sama

    Shiasu-sama

    Joined:
    May 30, 2018
    Posts:
    1
    That link says this now:

    "The requested page could not be found."