Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:04:23+00:00 2026-06-10T11:04:23+00:00

I want to connect to mysql server from C#. I found some code on

  • 0

I want to connect to mysql server from C#. I found some code on the net but somewhere there is something wrong because i get

A first chance exception of type ‘System.ArgumentException’ occurred in System.Data.dll

error.

private void Initialise()
    {
        server = "dns to server";
        database = "db_name";
        uid = "root";
        password = "password";
        string connectionString;
        connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                            database + ";" + "UID=" +
                            uid + ";" + "PASSWORD=" + password + ";";
          OR
        connectionString = "Server=xxx.no-ip.org;Database=rdb;"+
                "Uid=root;Pwd=wHt2%Zt;";
        connection = new MySqlConnection(connectionString);
        if (this.OpenConnection() == true)
            Console.Out.Write("SUCCESS");
        else
            Console.Out.Write("ERROR");
    }

private bool OpenConnection()  {
            try   {
                connection.Open();
                return true;
            }
            catch (MySqlException ex){                    
                switch (ex.Number) {
                    case 0:
                        MessageBox.Show("Cannot connect to server.  Contact administrator");
                        break;    
                    case 1045:
                        MessageBox.Show("Invalid username/password, please try again");
                        break;
                }
                return false;
            }
        }

I don’t get any message on the console. I added Mysql.Data as a reference to my project and i used using MySql.Data.MySqlClient;

I also tried connectig through gui but with no luck. Ideas ?

Edit 1 : with either connection string my program is still not working.

Edit 2 : OpenConnection method added.

Edit 3 : This is the error i get !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:04:24+00:00Added an answer on June 10, 2026 at 11:04 am

    p.s.

    http://www.connectionstrings.com/mysql

    probably you need to change your approach…use a webconfig or app config to setup and read your connectionstrings from the config…

    I would also recommend you to read this…

    http://www.codeproject.com/Articles/12300/An-ASP-NET-Application-Using-a-MySQL-Database

    UPDATE

    Based on your updated findings…there can be two problems, first double check your connectionstring, Second is to check if the user “root” has the required permissions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to connect to DB2 from excel macro...This is my code, but it
I want to use MYSQL server with my asp.net application. But i am not
I want to connect to a MySQL server database from an android client. I
I want to connect from home using SQL Server 2005 to another PC. I
In my application I want to connect SQL Server Express with Hibernate. But I
i'm want to store emails from Gmail into my mysql database. i found Inboxreader
I want to connect to MySQL from SBCL using CLSQL. I loaded CLSQL using
I want to connect to mysql database from my asp page.So for that as
I want to connect to my remote MySQL server through port forwarding. Unfortunately my
Hy. I want to display pictures from my mysql data base. Php Code: <body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.