Jump to content

MySQL.Data troubles...


FactsOfNature

Recommended Posts

[LOG] The file exists. Loading data....
[LOG] SERVER=localhost;PASSWORD=1234;UID=testa;DATABASE=testdb;
Could not load file or assembly 'System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
[LOG] System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at MySql.Data.MySqlClient.MySqlConnection.AssertPermissions()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at WoDRP.MySQL.MySQL.IsInConnection() in Y:\RAGEMP\server-files\dotnet\resources\WoDRP\MySQL\MySQL.cs:line 40


[LOG] Unsuccessful connection to database what the fuck

This is the error I get after I compile the mod. Excuse my goofy logs, I'm trying to learn how to work C# for fun and so far it's not been very fun at all.

 

Now, I have no clue what these errors are, in fact, most of the tutorials I followed and different mysql libraries give me almost the same set of errors whenever I try to launch the server. And yes, I do have the XAMPP server running in the background and the SQL is accessible that way. I have no clue why it doesn't wish to connect me, I've been at this for a week and found nothing interesting online, either.

 

A bit of an explanation will be appreciated.

As for the code, I'll post my MySQL.cs here.

 

using System;
using System.IO;
using System.Reflection;
using GTANetworkAPI;
using MySql.Data.MySqlClient;
namespace WoDRP.MySQL
{
    class MySQL
    {
        public static bool IsConnectionUp = false;
        public static MySqlConnection conn; 
        public String Host { get; set; }
        public String Username { get; set; }
        public String Password { get; set; }
        public String Database { get; set; }

        public MySQL()
        {
            this.Host = "localhost";
            this.Username = "root";
            this.Password = "";
            this.Database = "testdb";
        }

        public static void IsInConnection()
        {
            String FilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"SQLInfo.json");
            MySQL sql = new MySQL();
            if(File.Exists(FilePath))
            {
                Main.LogServer("The file exists. Loading data....");
                String SQLData = File.ReadAllText(FilePath);
                sql = NAPI.Util.FromJson<MySQL>(SQLData);
                String SQLConnection = $"SERVER={sql.Host};PASSWORD={sql.Password};UID={sql.Username};DATABASE={sql.Database};";
                conn = new MySqlConnection(SQLConnection);
                Main.LogServer(SQLConnection);

                try
                {
                    conn.Open();
                    Main.LogServer("Connection is successful.");
                    IsConnectionUp = true;
                }
                catch(Exception ex)
                {
                    Main.LogServer(ex.ToString());
                    Main.LogServer("Unsuccessful connection to database what the fuck");

                }

            }
            else
            {
                String SQLData = NAPI.Util.ToJson(sql);
                Main.LogServer("File does not exist. Creating one with base values...!");
                using (StreamWriter writer = new StreamWriter(FilePath))
                {
                    writer.WriteLine(SQLData);
                }
                Main.LogServer("File written successfully, re-loading the script..!");
                IsInConnection();
            }
        }

    }
}

 

Link to comment
Share on other sites

Okay. I figured it out.

 

What you should do is add   <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to your .csproj file, this fixed it for me and it works perfectly fine. I don't know what caused it before, but that seemed to fix it!

 

<PropertyGroup>
  w/e here
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

 

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...