我创建了一个类似于社交媒体应用的Android应用程序。我在用ASP.NET使用JSON获取数据或处理数据(如INSERT、UPDATE、DELETE)的web服务。我用的是MySQL数据库。
活跃用户数约2,5k,日均1,5k。
所以,我在完成了Web服务上的数据库处理后关闭了所有连接,但仍然存在那个问题或错误。
[WebMethod]
public string ABC(int x, string y)
{
using (con = new MySqlConnection(conString))
{
List result= new List();
result.Add(new Profile
{
posts= ""
});
List resultA= new List();
query= "SELECT COUNT(FollowId) FROM Followings WHERE FUserId = " + x;
con.Open();
cmd = new MySqlCommand(query, con);
dr = cmd.ExecuteReader();
string count = "0";
while (dr.Read())
{
count = dr[0].ToString();
}
dr.Close();
con.Close();
query= "SELECT COUNT(FollowId) FROM Followings WHERE FollowingUserId = " + x;
con.Open();
cmd = new MySqlCommand(query, con);
dr = cmd.ExecuteReader();
string count2 = "0";
while (dr.Read())
{
count2 = dr[0].ToString();
}
dr.Close();
con.Close();
query= "SELECT .... FROM Posts WHERE UserId = " + x+ " ORDER BY PostId DESC LIMIT 30";
con.Open();
cmd = new MySqlCommand(query, con);
dr = cmd.ExecuteReader();
int i;
int count3 = 0;
while (dr.Read())
{
count3++;
i = 0;
resultA.Add(new ClassA
{
postId = Convert.ToInt32(dr[i]),
postUrl = dr[++i].ToString(),
... = Convert.ToInt32(dr[++i])
});
}
dr.Close();
con.Close();
string json = "";
if (resultA.Count > 0)
{
json = JsonConvert.SerializeObject(resultA);
}
result[0].posts = json;
json = "";
if (result.Count > 0)
{
json = JsonConvert.SerializeObject(result);
}
return json;
}
}
这是我的网络方法的任何一个例子。我错在哪里?