Sign in to follow this  
SammyD86

Server c# MySQL

Recommended Posts

Hi ,

 

I'm trying a mysql connection for my server, but it stops and shuts down as soon as the event is called.

What could this be? does anyone know advice?

 

Is the database configuration so correct? I use the bridge server c # and client js

 

on Server c#

 [RemoteEvent("register2")]
    public void Register2(Client player, string username, string password)
    {
        Databasesql.Query($"INSERT INTO Playerdata(Username,Password) VALUES ('{username}','{password}')");

    }

and the database config c#

public static class Databasesql
{
    public static string myConnectionString = "SERVER=localhost;Database=gtav;UID=gta;PASSWORD=gtatest;";
   
    public static long Query(string Query)
    {
        using (var conn = new MySqlConnection(myConnectionString))
        {
            try
            {
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = Query;
                cmd.ExecuteNonQuery();
                conn.Close();
                return cmd.LastInsertedId;
            }
            catch (MySqlException ex)
            {
                NAPI.Util.ConsoleOutput($"[Database][Error] {ex.Message}");
             
                return -1;
            }
        }
    }

 

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.