I have read many of the similar questions. And understand that connecting directly to a DB is not best practice when published. However, for local prototyping, this is easiest to make quick tweaks while adjusting game components. I have trained myself well on the Unity Interface and am now working on scripting (with a background in C# web apps).
I am on Version 5.4.1f1. And trying to connect to a local MS SQL database table, SQL 2014. I also have Visual Studio 2015. When using a Web App, I can use the below code that works (concatenated for brevity sake).
When I plug this into a Unity Script, it gives me no errors. But when I attached and play, I get the message “All compiler errors must be fixed before you can enter playmode”. But of course, there are no errors in Visual Studio.
In Short, how can I alter the below code in to a Unity script so it would work (perhaps there is unique data classes in Unity, but I did not find any in the documentation…yet).
using System.Data.SqlClient;
…
…
SqlConnection conn = new SqlConnection(@“data source=EMAUCH2016\ERICLOCALMASTER;initial catalog=VirtualWorld;integrated security=True;”);
SqlCommand command = new SqlCommand("INSERT INTO TestConnection (TestID, DateTimeStampField, CubeCount) VALUES(NEWID(), GETDATE(), " + MyCount + "); ", conn);
I did revert the System.Data DLL to the necessary version (2.0.0.0); that was my obstacle yesterday. However, do you know where I can review compatible functions (and classes) for the mono version? That might have my answers, but I haven’t found that anywhere?
Good thought (coming from ASP.NET, I forgot about the console for errors)…It is referencing the DLL; I have repaired this by importing the Enterprise Services DLL. If anyone in the future is curious on the error, I have pasted it below.
PS- This has lead down a rabbit hole of additional errors around socket compatibility, but I’ve resolved a good portion. Hoping to complete the connection soon and will keep this thread updated once I do (or need more help).
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies.
at (wrapper managed-to-native) System.Reflection.MonoMethodInfo:get_method_info (intptr,System.Reflection.MonoMethodInfo&)
…
…
Internal compiler error at Assets/SphereController.cs(58,18):: exception caught while emitting MethodBuilder [SphereController::LogToDB]
The following assembly referenced from C:\Users.…\Assets\system.data.dll could not be loaded:
Assembly: System.EnterpriseServices (assemblyref_index=6)
Version: 2.0.0.0
Public Key: b03f5f7f11d50a3a
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (C:\Users.…\Assets).
Could not load file or assembly ‘System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies.