I’ve recently started trying to develop my own GTA RP Server. I’ve been able to accomplish some things that don’t require a database and how to translate LUA into C#. But I’m getting to the point now where I need to get my server connecting to a database so that I can store information off. I’m trying to use EntityFramework to connect to a SQL Server Database using Code First.
My setup right now is very simple. My database context is just this right now:
public partial class XeroRpContext : DbContext, IXeroRpContext
{
public XeroRpContext()
{
}
public DbSet<Player> Player { get; set; }
}
The Player Entity is the first table that I’m trying to create to be able to store Player information to be able to start setting up a whitelist and it’s just a class with properties. If I do anything that tries to open the database, then it throws exceptions saying that it can’t find the libraries Mono.Data.Tds and System.Data.OracleClient
Exception loading assembly Mono.Data.Tds: System.IO.FileNotFoundException: Unable to find the specified file.
Server stack trace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at (wrapper cominterop) CitizenFX.Core.IScriptHost:OpenHostFile (string)
at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost:OpenHostFile (string)
at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.OpenHostFile (System.String fileName) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MonoScriptRuntime.cs:254
at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:OpenHostFile (string)
at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:OpenHostFile (object,byte[]&,byte[]&,string)
Exception rethrown at [0]:
at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:OpenHostFile (string)
at CitizenFX.Core.InternalManager.LoadAssembly (System.String name) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\InternalManager.cs:112
Exception loading assembly Mono.Data.Tds: System.IO.FileNotFoundException: Unable to find the specified file.
Server stack trace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at (wrapper cominterop) CitizenFX.Core.IScriptHost:OpenHostFile (string)
at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost:OpenHostFile (string)
at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.OpenHostFile (System.String fileName) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MonoScriptRuntime.cs:254
at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:OpenHostFile (string)
at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:OpenHostFile (object,byte[]&,byte[]&,string)
Exception rethrown at [0]:
at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:OpenHostFile (string)
at CitizenFX.Core.InternalManager.LoadAssembly (System.String name) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\InternalManager.cs:112
Error invoking callback for event onResourceStart: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Could not load type of field 'System.Data.SqlClient.SqlConnection:sqlConnectionPools' (1) due to: Could not load file or assembly 'Mono.Data.Tds, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. assembly:Mono.Data.Tds, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756 type:<unknown type> member:<none>
at System.Data.Entity.Internal.LazyInternalConnection.Initialize () [0x000bd] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create (System.Data.Entity.DbContext context) [0x0002b] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x0009b] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00005] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Initialize () [0x0000e] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].get_InternalContext () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].ActOnSet (System.Action action, System.Data.Entity.EntityState newState, System.Object entity, System.String methodName) [0x0002a] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Add (System.Object entity) [0x00014] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.DbSet`1[TEntity].Add (TEntity entity) [0x00017] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at XeroRP.Whitelist.General.Server.Script.OnResourceStart (System.String resourceName) [0x0005e] in <5f0bc482949f497ca366f015ad629ad0>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00064] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:85
I Googled and found these libraries, but if I add them, then it complains about a ‘Password’ field not being set (I also worry that finding these libraries randomly on Google shouldn’t be necessary)
Error invoking callback for event onResourceStart: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingFieldException: Field 'Mono.Data.Tds.Protocol.TdsConnectionParameters.Password' not found.
at System.Data.SqlClient.SqlConnection.SetConnectionString (System.String connectionString) [0x0015c] in <c660f5a12cac430aa34fafb29a22e588>:0
at System.Data.SqlClient.SqlConnection.set_ConnectionString (System.String value) [0x00014] in <c660f5a12cac430aa34fafb29a22e588>:0
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<SetConnectionString>b__18 (System.Data.Common.DbConnection t, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext`1[TValue] c) [0x00007] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1[TInterceptor].Dispatch[TTarget,TInterceptionContext] (TTarget target, System.Action`2[T1,T2] operation, TInterceptionContext interceptionContext, System.Action`3[T1,T2,T3] executing, System.Action`3[T1,T2,T3] executed) [0x0000f] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString (System.Data.Common.DbConnection connection, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext`1[TValue] interceptionContext) [0x00042] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Infrastructure.SqlConnectionFactory.CreateConnection (System.String nameOrConnectionString) [0x00098] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalConnection.Initialize () [0x000bd] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create (System.Data.Entity.DbContext context) [0x0002b] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x0009b] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00005] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Initialize () [0x0000e] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].get_InternalContext () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].ActOnSet (System.Action action, System.Data.Entity.EntityState newState, System.Object entity, System.String methodName) [0x0002a] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Add (System.Object entity) [0x00014] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.DbSet`1[TEntity].Add (TEntity entity) [0x00017] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at XeroRP.Whitelist.General.Server.Script.OnResourceStart (System.String resourceName) [0x0005e] in <5f0bc482949f497ca366f015ad629ad0>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00064] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:85
I’ve also tried manually specifying the connection string, without and with the libraries mentioned above
public XeroRpContext()
{
Database.Connection.ConnectionString = "data source=xxx.xxx.xxx.xxx;database=dbname;user id=user_name;password=password;";
}
But it throws the same exceptions as above. I’ve also tried calling the DbContext constructor and passing in the connection string name
public XeroRpContext() : base("name=XeroRpContext")
{
}
But it throws an exception saying that it can’t find a connection string with the specified name
Error invoking callback for event onResourceStart: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: No connection string named 'XeroRpContext' could be found in the application config file.
at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel () [0x00072] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x0006f] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00005] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Initialize () [0x0000e] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].get_InternalContext () [0x00000] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].ActOnSet (System.Action action, System.Data.Entity.EntityState newState, System.Object entity, System.String methodName) [0x0002a] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Add (System.Object entity) [0x00014] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at System.Data.Entity.DbSet`1[TEntity].Add (TEntity entity) [0x00017] in <b7b192e5a05f4f14a14aa0d5b14aeeeb>:0
at XeroRP.Whitelist.General.Server.Script.OnResourceStart (System.String resourceName) [0x0005e] in <d8294710617648be984c00156502ac43>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00064] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:85
I’ve tried putting the App.config everywhere I can think of in my servers folders, but I don’t think it would matter since I tried specifying the connection string manually. Am I missing something? Can I actually connect to a SQL Server with EntityFramework? Or do I have to use a MySQL Server and the MySQL Connector? Can anyone help me and shed some light on whatever it is that I’m missing?
Sorry for the long post and thank you for your time and patience. Also let me know if there’s any more information that I should provide.