Hi guys,
I’m setting up a connection to a local database using WiFi. Everything works fine in the editor but when i build to PC standalone or Android, the application cannot connect. (i have Unity Pro + Android Pro)
The application starts but no data is being retrieved. The database gets updated every half second, so the application has to try and retrieve the data every (delayed) update.
The code i’m using is as followed:
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.SqlClient;
public class Database : MonoBehaviour
{
public int slowUpdateCount = 10;
private int i = 0; //Slow updating counter
private int j = 0; //GUI update counter (visual)
private string outputValueTime = "-";
private string outputValue = "-";
private bool noData;
private string connectionString = "Data Source=VLIPC\\SQLEXPRESS;Initial Catalog=Demo_Phoenix;Persist Security Info=True;User ID=****;Password=****;";
private SqlConnection sqlConnection;
private string sqlQuery;
private SqlDataAdapter sqlAdapter;
private DataTable dataTable = new DataTable();
// Use this for initialization
void Start ()
{
sqlConnection = new SqlConnection(connectionString);
sqlQuery = "SELECT TOP 1 [TagID], [Timestamp], [Value] FROM [Demo_Phoenix].[dbo].[Log] WHERE TagID = 9 AND Timestamp > '2013-09-12' ORDER BY Timestamp DESC";
sqlAdapter = new SqlDataAdapter(sqlQuery, sqlConnection);
sqlConnection.Open();
}
void Update()
{
if (i++ > slowUpdateCount)
{
GetData();
j++; //GUI update counter
i = 0; //Counter reset for slower updating
}
}
void GetData()
{
int recordsAffected = sqlAdapter.Fill(dataTable);
if (recordsAffected > 0)
{
noData = false;
outputValueTime = dataTable.Rows[0]["Timestamp"].ToString();
outputValue = dataTable.Rows[0]["Value"].ToString();
}
else
{
noData = true;
}
dataTable.Clear();
}
void OnGUI()
{
GUILayout.BeginArea(new Rect(Screen.width / 2 - 10, 50, Screen.width, Screen.height));
GUILayout.Label(sqlConnection.State.ToString());
GUILayout.Label("Update counter: " + j.ToString());
if (!noData)
{
GUILayout.Label(outputValueTime);
GUILayout.Label(outputValue);
}
else
{
GUILayout.Label("Error receiving data");
}
GUILayout.EndArea();
}
}
I got the code from here: Redirecting…
And i already tried this: CodePage 1252 not supported - works in editor but not in standalone player - Unity Answers
I put the System.Data.dll etc. files in the folder: Assets/Plugins. Stripping level is Disabled.
The question remains: Why does it work in the editor, but not on PC standalone or Android?
Edit: New development: put I18N.dll and I18N.West.dll + more I18N.whatever.dll inside the Assets/Plugins folder works for PC standalone. I can now establish a connection to the database using a standalone player. Android still has not changed… Am i missing a specific .dll?