我通过SSH从远程Mysql数据库获取数据到我的本地SQL服务器,然后从远程服务器删除所有数据;在我的C#ASP.net应用程序中(在IIS中运行)。从星期五开始它运行得非常好,但今天连接速度非常慢。我的连接代码是:
using (var client = new SshClient("vps.abc.com", 22, "username", "password"))
{
client.Connect();
var port = new ForwardedPortLocal("127.0.0.1", 3307, "localhost", 3306);
client.AddForwardedPort(port);
port.Start();
string connstr = "server=127.0.0.1;user=" + "user" + ";database=database;port=" + "3307" + ";password=" + "password" + ";";
using (MySqlConnection conn = new MySqlConnection(connstr))
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT DISTINCT * from formstable ORDER BY id DESC ", conn);
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
DateTime updated;
if (Convert.IsDBNull(dr["updated_at"]))
{
updated = Convert.ToDateTime(dr["created_at"]);
}
else
{
updated = Convert.ToDateTime(dr["updated_at"]);
}
var formsquote = new FormsQuote
{
//id = Convert.ToInt16(dr["id"]),
name = dr["name"].ToString(),
phone = dr["phone"].ToString()
};
FormsQuoteAdapter.Insert(formsquote);
}
}
dr.Close();
MySqlCommand cmd1 = new MySqlCommand("Delete FROM formstable ", conn);
cmd1.ExecuteNonQuery();
conn.Close();
}
port.Stop();
client.Disconnect();
我使用断点检查了行client.Connect();
花了很多时间。我不知道突然出了什么问题。任何人都可以帮我解决这个问题。谢谢