How to connect to MySQL with ASP.Net

Programming, error messages and sample code > sample code
If your application is using database, you might get the following error when publishing to the server:
"Unable to find the requested .Net Framework Data Provider.  It may not be installed."
Our server's default installed with MySQL Connector If you use other Connector, What you need to do is upload related version of Dll  MySql.Data.dll to your site bin folder.
There is no installation required on server,  you only need to upload the Mysql.Data.dll to the site "bin" folder. You can download the MySQL .NET connector in ''.
TheMySQL.Data.dll locates on the "Installation path\Assemblies". Defaultpath is "C:\Program Files\MySQL\MySQL Connector Net 6.0.3\Assemblies".
Below is an example, sample.aspx: 
<%@ Page Language="VB" debug="true" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<script language="VB" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

    Dim myConnection  As MySqlConnection
    Dim myDataAdapter As MySqlDataAdapter
    Dim myDataSet     As DataSet

    Dim strSQL        As String
    Dim iRecordCount  As Integer

        myConnection = New MySqlConnection(";Database=DBname;Uid=DB_ID;Pwd=DB_pw")

        strSQL = "SELECT * From [table name];"

    myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
    myDataSet = New Dataset()
        myDataAdapter.Fill(myDataSet, "[table name]")

    MySQLDataGrid.DataSource = myDataSet

End Sub 


<title>MySQL test</title>

<form id="Form1" runat="server">

<asp:DataGrid id="MySQLDataGrid" runat="server" />


In some application you are required to add the following lines in web.config. 
<compilation debug="true" urlLinePragmas="true">
<add assembly="MySql.Data,Version=, Culture=neutral,PublicKeyToken=C5687FC88969C44D"/></assemblies></compilation>
<authentication mode="Windows"/>
<customErrors mode="Off"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>