Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm trying to connect visual c# to mysql database. i have installed the mysql connector - connector/net, but i cant find mysql under the data source connections section. please assist!
Posted

refer this article
Connect C# to MySQL[^]
 
Share this answer
 
what operating system are you running and on what bit 32 or 64
if your os is running on 64 bit and if you install connector of 32 bit then it will not show you in the data source connection
 
Share this answer
 
Comments
abbasnafiu 6-Apr-13 10:43am    
i use win 7 32 bit : home premium
Try these
C#
private string server;
        private string port;
        private string database;
        private string uid;
        private string password;
        public string result;
        public string connectionString;
        public DBConnect()
        {
            Initialize();
        }

        private void Initialize()
        {
            server = "your ip address or localhost";
            port = "your port is here";
            database = "your database name";
            uid = "write user id here";
            password = "write password";
            connectionString = "SERVER=" + server + ";" + "PORT=" + port + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
            connection = new MySqlConnection(connectionString);
        }

        //open connection to database
        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;
            }
        }

        //Close connection
        private bool CloseConnection()
        {
            try
            {
                connection.Close();
                return true;
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }


if you have query again welcome
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900