Tom Gullen
Tom Gullen

Reputation: 61729

Can't connect to MySQL

<%@ WebHandler Language="C#" Class="SITEIMPORT" %>

using System;
using System.Web;

using MySql.Data;
using MySql.Data.MySqlClient;


/// <summary>
/// IMPORTS DATA FROM MYSQL TO OUR WEBSITE
/// </summary>
public class SITEIMPORT : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/plain";

        string connStr = "server=mysql2.DOMAINREMOVED.com;user=MYUSERNAME;database=DBNAME;port=3306;password=MYPASSWORD;";
        MySqlConnection conn = new MySqlConnection(connStr);
        try
        {
            context.Response.Write("Connecting to MySQL...");
            context.Response.Write("efef");      
            conn.Open();
            context.Response.Write("done");           

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());

        }
        conn.Close();
        Console.WriteLine("Done.");


    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

This prints the response:

Connecting to MySQL... efef

It doesn't say login failed, server not found, server blocked request, anything like that. No errors. Anyone know why "done" isn't printing out?

Upvotes: 0

Views: 343

Answers (2)

Shadow Wizard
Shadow Wizard

Reputation: 66389

ASP.NET has no Console.

Change Console.WriteLine to:

context.Response.Write

And you'll see whatever you send it. In your case, you'll see some error message.

Upvotes: 3

Babak Naffas
Babak Naffas

Reputation: 12561

Probably what's happening is the connection to your database is timing out for whatever reason. In the meanwhile, your page request is also timing out and therefore only reporting the output until the point where your page request timed out.

Upvotes: 1

Related Questions