How to get ASP.Net to work with MySql at x10Hosting

spangeman

New Member
Messages
6
Reaction score
2
Points
0
Pre-reqs
First read this post to get ASP.Net to work at x10Hosting
http://forums.x10hosting.com/tutorials/102062-how-get-asp-net-work-x10hosting.html

Use your C Panel to create a database (MySQL Databases) and create tables and data (phpMyAdmin)

Steps
1. Create a bin folder in the root of your public_html directory

2. Get the two MySql dot net connector dlls and place them in the bin folder
http://dev.mysql.com/downloads/connector/net/6.2.html
MySql.Data.dll
MySql.Web.dll

You may already have these on your PC if you have been developing against a MySql database.

Remember you are running ASP.Net on a Linux Mono box so it is cAsE SenSiTive, please ensure the dll names remain the same as they were when you downloaded them.

3. There are a variety of ways to write the asp.net page but the key point is the connection string must use mysql-chopin.x10hosting.com for the server and not localhost which will work in php and drove me nuts for a couple of days.

4. Example 1
This is how I have set mine up and it is working, you will need to edit the connection string to your own database, username and password. Also the SQL statements table name will need changing to your own tablename.
The asp code came from this tutorial - http://townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux


web.config
Code:
<?xml version="1.0" ?>
    <configuration>
         <appSettings />
         <connectionStrings />
         <system.web>
              <customErrors mode="Off" />
         </system.web>
   </configuration>
   <configuration>
  <system.web>
    <compilation>
      <assemblies>
      <add assembly="MySql"/>
        <add assembly="MySql.Data"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>
aspx Page
Code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>CD cat</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script runat="server">
    private void Page_Load(Object sender, EventArgs e)
    {
        string connectionString = "server=mysql-chopin.x10hosting.com;Database=MyDatabase;userid=MyUserId;password=MyPassword;Pooling= false;";
       MySqlConnection dbcon = new MySqlConnection(connectionString);
       dbcon.Open();

       MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM CDs", dbcon);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "result");

       dbcon.Close();
       dbcon = null;

       ArtistsControl.DataSource = ds.Tables["result"];
       ArtistsControl.DataBind();
    }
    </script>

  </head>

  <body>
    <h1>Artists</h1>
    <asp:DataGrid runat="server" id="ArtistsControl" />
  </body>

</html>
5. Example 2

thegriff has replied to my queries about this with another example, he has placed the connection string in his web.config file and not bothered with any references.
http://forums.x10hosting.com/programming-help/103929-asp-net-mysql.html#post592093
 

tvmtuan

New Member
Messages
1
Reaction score
0
Points
0
Thank you for your post, but when I ping mysql-chopin.x10hosting.com, there's no reply. When I ping mysql.x10hosting.com, I received replies. So I put mysql.x10hosting.com into server in connection string. My Connection string is something like this:
Code:
server=mysql.x10hosting.com;Database=DBName;userid=username;password=password;Pooling=false
When I run my page, I received an exception Unable to connect to any of the specified MySQL hosts. Does anyone have a solution for this^^
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
My Connection string is something like this:
Code:
server=mysql.x10hosting.com;Database=DBName;userid=username;password=password;Pooling=false

The server name should be "localhost"; a search on the forums turns up many threads containing this information (admittedly, alongside threads that don't have the information with that particulary query).
 

zegnhabi

Member
Messages
44
Reaction score
2
Points
8
Asi es la solucion que propone el compañero es valida y si jala, jeje
 

linearity

New Member
Messages
1
Reaction score
0
Points
0
I just can't get it to work, what am I doing wrong???

I have tried to follow this tutorial, but I keep getting and error that says: "Unable to connect to any of the specified MySQL hosts." I have placed the connector dlls into a bin folder in public_html, and if I comment out the line with the call dbConn.Open() the function executes. What am I doing wrong? I am trying to follow the example as shown at http://www.mono-project.com/MySQL, and if I can get the db to open, I will start messing around with queries, but it won't open.

Here is my web.config

<?xml version="1.0" ?>
<configuration>
<appSettings />
<connectionStrings />
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="MySql"/>
<add assembly="MySql.Data"/>
</assemblies>
</compilation>
</system.web>
</configuration>

Here is my Default.aspx.cs file

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = "Server=mysql-chopin.x10hosting.com;" +
"Database=xxx;" +
"User ID=xxx;" +
"Password=xxx;" +
"Pooling= false;";

IDbConnection dbcon;
dbcon = new MySqlConnection(connectionString);
dbcon.Open();

dbcon.Close();
dbcon = null;
}
}
 
Top