将visual C#连接到mysql数据库 [英] connecting visual C# to mysql database

查看:89
本文介绍了将visual C#连接到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将visual c#连接到mysql数据库。我已经安装了mysql连接器 - connector / net,但我无法在数据源连接部分找到mysql。请协助!

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!

推荐答案

参考这篇文章

将C#连接到MySQL [ ^ ]


你正在运行什么操作系统,如果你的操作系统正在运行,那么32或64位是什么?b $ b在64位上,如果你安装32位连接器,那么它不会在数据源连接中显示
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


试试这些

Try these
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


这篇关于将visual C#连接到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆