Search Unity

Unity 4 + SQL Database

Discussion in 'Editor & General Support' started by hrjunker, Apr 28, 2013.

  1. hrjunker

    hrjunker

    Joined:
    Nov 15, 2011
    Posts:
    26
    Hi there

    I am working on a project where I am using a database to store and retreive information about users of my app. Now I am trying to connect to the database on Azure with this script:

    Code (csharp):
    1.     private const string connectionString =
    2.         "Server=tcp:[Server].database.windows.net,1433;" +
    3.         "Database=[DatabaseName];" +
    4.         "User ID=[username]@[Server];" +
    5.         "Password=[password];";
    6.  
    7.     void Start () {
    8.         OpenConnection();
    9.     }
    10.  
    11.     private static void OpenConnection()
    12.     {
    13.         using (IDbConnection dbcon = new SqlConnection(connectionString))
    14.         {
    15.             dbcon.Open();
    16.             using (IDbCommand dbcmd = dbcon.CreateCommand())
    17.             {
    18.                 dbcmd.CommandText = "SELECT * FROM [dbo].[User]";
    19.  
    20.                 IDataReader reader = dbcmd.ExecuteReader();
    21.                 while (reader.Read())
    22.                 {
    23.                     Debug.Log((string)reader["profile_Name"]);
    24.                 }
    25.                 dbcon.Close();
    26.             }
    27.         }
    28.     }
    NOW! The "funny" thing is that if I use this code in a normal C# console project this works perfectly, but when I run it in Unity I get the following error

    As I understand there are some different versions of the System.Data.dll and I have tried with every version that I could come across, but non have worked yet.

    Anyone have it working? or any suggestions to what I could do to solve this issue?
     
  2. rapidfirestudio

    rapidfirestudio

    Joined:
    Jan 31, 2013
    Posts:
    73
    Correct me if I'm wrong in your case but isn't that insanely insecure?

    You're probably going to want to setup an http interface to your data and use Unity's WWW class.
     
  3. montyfi

    montyfi

    Joined:
    Aug 3, 2012
    Posts:
    548
    That's right, NEVER do that on client! Your database will be hacked next minute after publishing that.
     
  4. hrjunker

    hrjunker

    Joined:
    Nov 15, 2011
    Posts:
    26
    Well this was also only as an initial testing phase, and I am aware of the serurity risks in this setup. I guess I just have to do a web interface from the start then.
     
  5. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    When i try to use postgresql with Unity in server, Unity crashes, also would like to know how make it work