- Home /
 
Connection to MSSQLServer 2008R2 works fine in Unity Editor, but when it deployed into android device, the connection cannot be open. What should I do?
I am so happy when trying connecting to sql is success in unity3D editor. But not when it deployed to device.
I have copied System.Configuration.dll, System.Data.dll, System.Data.Linq.dll, System.EnterpriseServices.dll to Assets folder.
Here is my code:
using UnityEngine; using System.Collections; using System.Data; using System.Data.SqlClient;
public class FS_SQLConnect : MonoBehaviour {
 public UILabel label;
 public string ServerName;
 public string DatabaseName;
 public string UserID;
 public string Password;
 
 public UILabel status;
 
 
 private static IDbConnection dbConnection;
 
 public bool openSqlConnection() {
 
               //check 1
         string connectionString = 
          "Server="+ ServerName +";" +
          "Database="+ DatabaseName + ";" +
          "User ID="+ UserID +";" +
          "Password=" + Password";
         
 
               //check 2
     dbConnection = (IDbConnection)new SqlConnection(connectionString);
 
               //check 3
     dbConnection.Open();
         
 
               //check 4
     Debug.Log("Connected to database.");
         return true;
     }
     catch(SqlException ex)
     {
         label.text = ex.ToString();
         return false;
     }
     catch(UnityException ex)
     {
         label.text = ex.ToString();
         return false;
     }
     return false;
 }
 
               When deployed to device, it always stop in dbConnection.Open(); //check 3
I have try:
Connecting my PC and android device to same Wifi, and try to ping from device to PC(worked).
Creating Hotspot from PC, then android device connected to it
Enable TCP/IP Connection in SQL Server Network Configuration for MSSQLSERVER
When I give wrong PC IP Address, the device says an error that server could not be found When I give wrong password to connectionString, the device says failed to Login
But when I give correct IP, DatabaseName, UserID and password. There is 2 condition: When firewall is on, it says: System.Data.SqlClient.SqlException: Timeout expired.
When firewall is off: nothing happen, when I'm trying to change a label text in every "check" (comment on my code), it stop in check 3(means it failed when opening connection). and connectionState says it still closed :(
Sorry for long description. Please help me :(
Thank you :)
Your answer
 
             Follow this Question
Related Questions
Database works on unity editor,but not on android device 1 Answer
Storing Constant data in a mobile game 0 Answers
Application.genuine 0 Answers
how to read a Microsoft access database in unity 3d 0 Answers
Sqlite4Unity3d difficulties 1 Answer