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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.