I already tried searching and reading posts and questions here, but I still cannot find the answer I need. Hope that someone can help me...
I'm working on Visual Studio 2012, and I'm trying to connect to a hosted database in MySQL, which uses phpMyAdmin.
I have an example here which is used to connect to a SQLServer database, which goes like this:
new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ecomerce.mdf;Integrated Security=True;User Instance=True");
(I know it's connecting to a local datatable, but that's not important)
I believe I should find some different 'new' type to instantiate, in order to connect to a MySQL database, as ' new SQLConnection' is for SQLServer. A friend told me I should use a 'MySQL Data Connection' from Oracle. I downloaded it and installed it, but really don't see any changes. What should I do? What I am supposed to do to connect to my database?
A simple connection string for MySql is (in C#)
MySqlConnection cnn = new MySqlConnection("Server=myServerAddress;" +
"Database=myDataBase;" +
"Uid=myUsername;" +
"Pwd=myPassword;");
Of course you should add a reference to the MySql.Data.dll appropriate for your version of MySql and add a using statement to reference the namespace in your code.
Other examples of connectionstring variations could be found at connectionstrings.com
string strConn = @"Server=localhost;Database=Bancodados;Uid=root;Pwd='numsey';Connect Timeout=30;";
conn = new MySqlConnection(strConn);
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.