Unity .NET 4.6 framework causing SqlConnection ConnectionString to throw exception.
Hello,
I hope someone can help me with this issue. Basically I'm trying to read multiple tables from a database. I'm using System.Data to open up a connection and then loading the tables using DataTable. This process works flawlessly in the Unity Play window, however when the project is built, nothing happens. I tracked my issue using file writing output to the point where I am setting the connection string. I am using a try catch statement to get the exception that is being thrown. I will list the exception later on in the post.
What I find odd about this problem is that this works flawlessly in the Unity Play window but does not work when built and run. I'm going to try to give as much information as possible in this post.
Version Information:
Unity Version: 2017.1.1f1 Personal
.NET Version: Experimental (.NET 4.6 Equivalent)
Api Compatibility Level: .NET 4.6
Visual Studio 2017
Target Framework: .NET Framework 4.6
Microsoft Windows 10
public System.Enum OpenNewConnection(string _connectionString)
{
try
{ connection = new SqlConnection(_connectionString); }
catch (Exception ex)
{ wm.WriteToFile(ex.ToString()); }
connection.Open();
isOpen = connection.State;
return connection.State;
}
_connectionString is as follows ( to replace sensitive information) = "Server=;Database=;User ID=;Password=;"
When I run this code in the play window, the connection is created properly with the connection string format provided above. However when I try to build the project, the connection is never opened since the connection string is not set properly. The catch exception is as follows:
System.MissingFieldException: Field 'Mono.Data.Tds.Protocol.TdsConnectionParameters.Password' not found. at System.Data.SqlClient.SqlConnection.SetConnectionString (System.String connectionString) [0x00188] in :0 at System.Data.SqlClient.SqlConnection.set_ConnectionString (System.String value) [0x00017] in :0 at SQLConnection.OpenNewConnection (System.String _connectionString) [0x00064] in :0
Answer by NineOverZero · Feb 12, 2018 at 11:27 AM
You need to go into your "C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0" folder and copy the "Mono.Data.Tds.dll" DLL into your "[application_name]_Data\Managed" folder which will be in the same location as your build .exe. This will overwrite the "Mono.Data.Tds.dll" inside the "[application_name]_Data\Managed" folder, but this is what you want to do. Hope this helps
Yes, the problem before is solved, but a new problem occurred.
System.NotSupportedException: Encoding 936 data could not be found. $$anonymous$$ake sure you have correct international codeset assembly installed and enabled.
at System.Text.Encoding.GetEncoding (System.Int32 codepage) [0x0024f] in /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/text/encoding.cs:554
at $$anonymous$$ono.Data.Tds.TdsCharset.GetEncodingFromLCID (System.Int32 lcid) [0x00025] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.TdsCharset.GetEncodingFromLCID (System.Byte[] collation) [0x00007] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.TdsCharset.GetEncoding (System.Byte[] collation) [0x00012] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.Protocol.Tds.ProcessEnvironmentChange () [0x00253] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x00125] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.Protocol.Tds.NextResult () [0x0004a] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00005] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.Protocol.Tds70.Connect ($$anonymous$$ono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x005bc] in <eee0753a23f545e996afde018cb416b2>:0
at $$anonymous$$ono.Data.Tds.Protocol.Tds80.Connect ($$anonymous$$ono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in <eee0753a23f545e996afde018cb416b2>:0
at System.Data.SqlClient.SqlConnection.Open () [0x001ac] in <36a1f9473d7045a2ae4ffb1098313dbe>:0
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnderWater3D.DataProvider:Connect() (at D:\UnderWaterRobot\UnderWaterRobot\Assets\Script\DataBase\DataProvider.cs:45)
UnderWater3D.Show$$anonymous$$odelInfo:Awake() (at D:\UnderWaterRobot\UnderWaterRobot\Assets\Script\UIScript\Show$$anonymous$$odelInfo.cs:42)
Your answer
Follow this Question
Related Questions
How do I resolve, get_isActiveAndEnabled can only be called from the main thread error 1 Answer
Replace C# Lambda Operator 1 Answer
Compiler error at start of mono develop and visual studio 1 Answer
Help with high score SQL table and the C# scripts 0 Answers
Build a UWP app in c# with scripting backend IL2CPP 0 Answers