Question

I cannot connect to MySql from my C# windows form application. I also have posted a question already in invalid username/password

but got nothing solution. Suppose my website name is www.google.com and cpanel user name is imrancpanel, my cpanel password is imranpd, I create a database imrandb, create a database user imrandbuser and check all permissions to this user for this website. whats the problem in this code?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace CSharpMySql
{
    class Program
    {
        static string getString(string msg)
        {
            Console.Write(msg);
            return Console.ReadLine();
        }

        static void Main(string[] args)
        {
            string myConnectionString = @"server=google.com;userid=imrancpanel_imrandbuser;
            password=imranpd;database=imrandb";

            MySqlConnection con = null;
            MySqlDataReader reader = null;
            string cretablestr = "CREATE TABLE IF NOT EXISTS AutoCaptchaTable (LoginID       char(25), Password char(25), ActivationStatus char(25), NofTransactions int );"

            try
            {
                //MySqlConnection 
                conn = new MySqlConnection(myConnectionString);
                conn.Open();
                MessageBox.Show("OK");
                conn.Close();
            }
            catch (MySqlException ex)
            {
                switch (ex.Number)
                {
                    case 0:
                    MessageBox.Show("Cannot connect to server.  Contact administrator");
                    break;
                    case 1042:
                    MessageBox.Show("Can't get hostname address. Check your internet connection. If does not solve, contact Administrator");
                    break;
                    case 1045:
                    MessageBox.Show("Invalid username/password");
                    break;
                }
            }
        }
    }
}
Was it helpful?

Solution 2

Enable remote access in cpanel by adding host(IP OR DOMIAN etc)

OTHER TIPS

Most website hosters don't allow remote access to MySQL only with localhost

you need to create a webservice with php to allow that or get an alternative

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top