简体   繁体   中英

Is it possible to connect to MySQL database in a remote Linux machine with Visual Studio in Windows

I've been researching forever for the connecting strings (VB or C#) to connect to a remote MySQL database that is currently hosted (by Hostgator.com) in a shared linux box. Is it possible? If so, can anyone direct me to the codes or wizard on how to do this. I'm using 2010 Visual Studio Express on my desktop in Windows 7. Your help would be so greatly appreciated.

Update: I kept getting "Authentication with old password no longer supported, use 4.1 style password" and after numerous hours of searching online, I finally contacted my hosting company to request them to update the user's password to longer hashes. Apparently, I could not have done it myself. It seems inconvenient, but at least it's working now.

Yes it is, you will need to reference MySql.Data.dll which is part of MySQL connector to .NET. Download from here .

After this connection is very similar to MS SQL one.

private const string ConnectionString = "SERVER=YourServer;DATABASE=YourDB;UID=UserName;PASSWORD=UserPassword;";
using (var mcon = new MySqlConnection(ConnectionString))
            using (var cmd = mcon.CreateCommand())
            {
                mcon.Open();
                //you actions
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM