<%@ 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;
}
}
}
这会打印响应:
Connecting to MySQL... efef
它不会说登录失败、找不到服务器、服务器阻止请求等等。没有错误。有人知道为什么“完成”没有打印出来吗?
ASP.NET 没有控制台。
将 Console.WriteLine
更改为:
context.Response.Write
您将看到您发送的任何内容。在您的情况下,您会看到一些错误消息。
我是一名优秀的程序员,十分优秀!