Sign in to follow this  
DjEnzo

How to use MySQL

Recommended Posts

Hi guys!

Am about to start programming my new server, but I cannot use MySQL. 

I started with this tutorial -> https://rage.mp/forums/topic/1807-c-getting-started-debugging/

This is how my code looks like:

using System;
using System.Data;
using GTANetworkAPI;
using MySql.Data.MySqlClient;

namespace GTV
{
    class MySQL
    {
        private string connectionString = "SERVER=localhost;" + "DATABASE=gtv;" + "UID=root;" + "PASSWORD=;" + "SslMode=none";

        public bool FirstConnect()
        {
            MySqlConnection db = new MySqlConnection(connectionString);
            db.Open();
            string state = db.State.ToString();
            NAPI.Util.ConsoleOutput(state);
            if (db.State == ConnectionState.Open) return true;
            else return false;
        }


    }
}

And here my pretty long exception:

Spoiler

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at void System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, string ilPath, string niPath, ObjectHandleOnStack retAssembly)
   at Assembly System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(string assemblyPath)
   at Assembly System.Reflection.Assembly.LoadFrom(string assemblyFile)
   at Assembly System.Reflection.Assembly.LoadFromResolveHandler(object sender, ResolveEventArgs args)
   at RuntimeAssembly AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, string assemblyFullName)
   --- End of inner exception stack trace ---
   at new MySql.Data.MySqlClient.MySqlField(Driver driver)
   at MySqlField[] MySql.Data.MySqlClient.Driver.GetColumns(int count)
   at void MySql.Data.MySqlClient.ResultSet.LoadColumns(int numCols)
   at new MySql.Data.MySqlClient.ResultSet(Driver d, int statementId, int numCols)
   at ResultSet MySql.Data.MySqlClient.Driver.NextResult(int statementId, bool force)
   at bool MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySqlDataReader MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   --- End of inner exception stack trace ---
   at MySqlDataReader MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at Dictionary<string, string> MySql.Data.MySqlClient.Driver.LoadServerProperties(MySqlConnection connection)
   at void MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
   at void MySql.Data.MySqlClient.MySqlConnection.Open()
   at bool GTV.MySQL.FirstConnect() in C:\Users\Kacper\Documents\GT-V\GTV\GTV\MySql.cs:line 15
   at void GTV.Main.OnResourceStart() in C:\Users\Kacper\Documents\GT-V\GTV\GTV\Main.cs:line 12
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at GTANetworkInternals.ScriptingEngine.InvokeVoidMethod(String method, Object[] args)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at GTANetworkInternals.EventHandler.ParseEx(Event _event, ScriptingEngine engine, Object[] arguments)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at GTANetworkInternals.GameServer.StartResource(String resourceName, String parent)

What did I do wrong? Thank you for your help.

Share this post


Link to post
Share on other sites

You are missing

System.Text.Encoding.CodePages.dll

For me it helps if i copy it from the runtime folder to my server-resource.

 

Runtime Folder: /RAGEMP/server-files/bridge/runtime

Your Resource: /server-files/bridge/yourresourcename

 

Dont know if its the best or right way but it works :)

Edited by Flashrex

Share this post


Link to post
Share on other sites

I found my solution 2 hours ago.

You need to copy all dll's your gamemode use to the runtime folder.

I added also to meta.xml this:

<assembly ref="MySql.Data.dll" />

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.