Why does my application connect to a local database over wifi in the editor but not in Android?

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?

Solution by the user Tak on Unity3D irc:

private string connectionString = "Data Source=VLIPC\\SQLEXPRESS;Initial Catalog=Demo_Phoenix;Persist Security Info=True;User ID=****;Password=****;";

change Data Source to: Data Source=ipadress\\SQLEXPRESS; for example: Data Source = 192.168.0.2\\SQLEXPRESS;

Data Source=VLIPC\\SQLEXPRESS; Works on Windows

Data Source = 192.168.0.2\\SQLEXPRESS; Works on Windows and Android

Sorry for commenting on zombie thread but this is likely not a problem with your code. By default the Unity Editor contains the following dll’s:

I18N.CJK.dll

I18N.dll

I18N.MidEast.dll

I18N.Other.dll

I18N.Rare.dll

I18N.West.dll

These can be found where you initially installed unity. By default this location is C: > Program Files > Unity > Editor > Data > Mono > lib > mono > 2.0

You need to create a folder “Plugins” in your Assets folder in your Unity project, then copy all of the above dll’s into that new Plugins folder.

Also in the future, you can find the exact error by going to the EXECNAME_DATA folder that was created with your build and finding the output_log.txt file. That file contains all the Debug statements that would have been printed to the console had you run it in the editor. One of those is likely your error code.