"My ASP.Net script works on my server but it does not work on your server."

MySQL Connection

Sometimes, you may be wondering how to make your ASP.Net script connect to the MySQL database that you have just got from us. You might have received information like this from us:

Host :
Database name : mydatabase_db
Username : mydbuser
Password : mydbpass

There are many ways to connect to the database. Here is just one example. The below is a simple example of how you can connect to your database, using the information we gave you above, do a simple query, and display the results.

<%@ Page Language="C#" AutoEventWireup="False"
EnableSessionState="False" EnableViewState="False" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>

<script runat="server">
private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" +

protected override void OnInit(EventArgs e)

using(OdbcConnection con = new OdbcConnection(ConnStr))
using(OdbcCommand cmd = new OdbcCommand("SELECT uid, fname, lname FROM mytable", con))
dgrAllNames.DataSource = cmd.ExecuteReader(
CommandBehavior.CloseConnection |

<title>Displaying Records from MySQL 'mytable' table</title>
body { font: 100% Verdana; }

<p align="center">All records in the 'mytable' table:</p>

<asp:DataGrid ID="dgrAllNames" HorizontalAlign="Center"
CellPadding="3" Runat="server" />