I used this code to connect my Unity project to my MySql database:
public void SetupSQLConnection()
{
Debug.Log("Connection Function Started");
if (connection == null)
{
Debug.Log("If connection == null");
try
{
Debug.Log("Try block started");
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
connBuilder.Server = "localhost";
connBuilder.UserID = "root";
connBuilder.Database = "therapygame";
connBuilder.Password = "";
connBuilder.OldGuids = true;
Debug.Log("String set");
connection = new MySqlConnection(connBuilder.ConnectionString);
Debug.Log("new MySqlConnection");
connection.Open();
Debug.Log("connection");
}
catch (MySqlException ex)
{
Debug.LogError("MySQL Error: " + ex.ToString());
}
}
}
This works fine when running my project in the Unity3d editor. However, when I build the WebGL, it no longer connects to the database.
The error happens between the Debug.Logs of "new MySqlConnection" and "connection". In other words, it is failing at the connection.Open(); statement.
Here is the console log in Google Chrome:
SystemException: Thread creation failed.
Rethrow as TypeInitializationException: The type initializer for 'System.Threading.Timer.Scheduler' threw an exception.
Rethrow as TypeInitializationException: The type initializer for 'System.Threading.Timer' threw an exception.
Rethrow as TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlPoolManager' threw an exception.
(Filename: currently not available on il2cpp Line: -1)
And here is the source of that error (it is so large that I had to break it apart into sections)(see following section to know what to look for):
https://0bin.net/paste/-28c3BvLx+Nx+Q+L#ltyOWWb+IembwSAgNKzPCRwvI5MkPOrUfgOAs3i4R+f
https://0bin.net/paste/ZleyLDeOcgr3kj-e#OPVr3oIC8-mcO9mXB1pV/+ONcdnUB+3I1RCy37/NI+p
https://0bin.net/paste/+rbHWsKmXhIXM50A#PaAFLCeDJZzIQTWczYbDepmubFhSaeDWqzcB+ItUTnb
https://0bin.net/paste/VdNv2NA8K0--ZXNM#fomzOVZ9iNOJDHequiSAbuv6I3lxDXXL+E5WK6GPKZv
https://0bin.net/paste/zcDPoycv5lqbjRcA#h0WNQdMSU4VtdIbwzOByW5csu68FERPvEdOKJz9oUeA
Copy this and paste it into ctrl+f find:
function _JS_Log_Dump(ptr, type) {
var str = Pointer_stringify(ptr);
if (typeof dump == "function") dump(str);
switch (type) {
case 0:
case 1:
case 4:
console.error(str);
return;
case 2:
console.warn(str);
return;
case 3:
case 5:
console.log(str);
return;
default:
console.error("Unknown console message type!");
console.error(str);
}
}
the lines that are in question are
case 4:
console.error(str);
I have included System.Data.dll and MySql.Data.dll to my Visual Studio references, and also all the I18N files. I have also put those files in my built project file path.
Please tell me if you need additional information, I tried to include everything I thought was relevant.