skip to Main Content

I need your help. I’m trying to get into servers on my own. I was searching yesterday about it a bit, I saw one code here and also tried one from a YT video. Not exactly sure what I’m doing. I’ve created an online SQL database on this page https://remotemysql.com/. I’ve created a database and table and manually assigned some values for further testing. Then I started to look for some code to open the database

using MySql.Data.MySqlClient;
using System;

namespace SQLTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world"); //for testing
            string server = "Momoos-PC";
            string database = "Score";
            string uid = "iqWUaqal5x";
            string password = "Q4tcOaJXdW";
            string connectionString;
            connectionString = "SERVER=" + server + "; PORT = 3306 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
            MySqlConnection mycon = new MySqlConnection(connectionString);
            mycon.Open(); //error
            Console.WriteLine("Connection Open  !");
            mycon.Close();
        }
    }
}

So I understand that there is a need for some connection string but I’m not sure how it should look like or what library to use (mysqlconnection/sqlconnection).

string server – I’m not sure what to write here but when I’m in the PHPmyAdmin it says Server: localhost, But it shouldn’t be because it’s online no? So I wrote the localhost as my PC’s name. Idk.

Then there is a string database. Don’t know if they mean the name of the database – like the thing that contains all small tables or they mean the exact table to which to connect. Score is the name of table containing some values.

UID is I think username for logging into the database – I used the one I use to access PHPMyAdmin. (You can use it too, It’s just free database, nothing important in it)

Password – password used to log into PHPMyAdmin.

Yes, and the error, AggregateException: 192.168.100.3:3306 No connection could be made because the target machine actively refused it. 192.168.100.3:3306

Please help me or point me to a good tutorial. I would like to have an online SQL server. Most of tutorials are for local server – Idk, should I watch them? Is it the same as an online server? How to make the transition to online then?

2

Answers


  1. From the info given in your code then you should be able to connect remotely to that database with these changes

    string server = "removemysql.com";
    string database = "iqWUaqal5x";
    string uid = "iqWUaqal5x";
    string password = "Q4tcOaJXdW";
    string connectionString;
    connectionString = $"SERVER={server};PORT=3306;DATABASE={database};UID={uid};PASSWORD={password};";
    

    Notice that I assume that the database name is the same as your user name. I have tried to use this service (and at first sight it seems pretty done) and the first database has the same name as the user.

    IMPORTANT
    Be sure to read their FAQ. The limitations on their service could be a problem for real applications.

    Login or Signup to reply.
  2. Try if that works. I believe the issue was the incorrect server name. Also, when you use Uid as user id, try to use Pwd for password.

    Check out the official docs on the same : https://remotemysql.com/tutor4.html

    Please edit the answer and remove if those are actual credentials.

    using MySql.Data.MySqlClient;
    using System;
    
    namespace SQLTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello world"); //for testing
                string server = "remotemysql.com";
                string database = "Score";
                string uid = "xxxx";
                string password = "xxxx";
                string connectionString;
                connectionString = "SERVER=" + server + "; PORT = 3306 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PWD=" + password + ";";
                MySqlConnection mycon = new MySqlConnection(connectionString);
                mycon.Open(); //error
                Console.WriteLine("Connection Open  !");
                mycon.Close();
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search