So after some tries I figured out I needed a driver for this. I've installed the Components from the links below. But I still can't find any SQL references when I try to add them? I'm wondering if anyone would know the reason for this? I just started with asp.net. I've found several other questions regarding code for connecting but I can't find anyone who've had trouble with the Connector/components before?
MYSQL connector http://dev.mysql.com/downloads/connector/net/5.0.html
Microsoft Data Access Components (MDAC) 2.8 http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en
I am using Visual Studio.
To Connect to a MySQL Database Using ASP.NETFind your database's connection strings (Plesk). Note: Change the your password value to your real database password value. Using Microsoft Visual Studio . NET create an ASP.NET Project.
To Connect to a MySQL Database Expand the Drivers node from the Database Explorer. Right-click the MySQL (Connector/J driver) and choose Connect Using.... The New Database Connection dialog box is displayed. In the Basic Setting tab, enter the Database's URL <HOST>:<PORT>/<DB> in the corresponding text field.
Moreover, to connect using MySQL Connector/NET for Windows Application, we can do it through the following code. The above code can be used to integrate MySQL in C# in the native Windows authentication and CRUD operations can then be performed on top of it. We'll learn more about it in our next article.
Connector/NET includes full support for: Features provided by MySQL Server, up to and including the MySQL 8.0 release series. MySQL as a document store (NoSQL), along with X Protocol connection support to access MySQL data using X Plugin ports.
Right click on References, then select "Add Reference". Browse and select Mysql.Data.dll
.
The dll should be found in the installation directory of the connector you downloaded.
Finally, in code:
using MySql.Data.MySqlClient;
And, sample connection:
MySqlConnection connection = new MySqlConnection("Database=database_name;Data Source=server_domain_or_ip;User Id=mysql_user;Password=mysql_password");
connection.Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from mytable";
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//reader.GetString(0)
//reader["column_name"].ToString()
}
reader.Close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With