"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:

===========================================================
MySQL ACCOUNT LOGIN INFO
===========================================================
Host : 202.157.142.106
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};" +
"Server=202.157.142.106;Database=mydatabase_db;uid=mydbuser;pwd=mydbpass;option=3";

protected override void OnInit(EventArgs e)
{
base.OnInit(e);

using(OdbcConnection con = new OdbcConnection(ConnStr))
using(OdbcCommand cmd = new OdbcCommand("SELECT uid, fname, lname FROM mytable", con))
{
con.Open();
dgrAllNames.DataSource = cmd.ExecuteReader(
CommandBehavior.CloseConnection |
CommandBehavior.SingleResult);
dgrAllNames.DataBind();
}
}
</script>

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

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

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

</body>
</html>