?????????????????????4?????????Щ?????DBA????????????????CPU??ú??????SQL???????????????????????????????????
?????????к??????????????????????????????????????????????????
???????????1.????????sql???????????????
????????????????????SQL??????????????????????????????????????????????ò??????ò????????????鷳????????????????????????SQL?????????ò???????????????????鷳????????SQL??????OK
???????????2.????????????????????????????????????????
????????????????????????????????????????????д??????????????????ü????????????д????鷳??????????????????????????????sql??????????SqlParameter????????SqlDbType??size????????????????????д?????к???????????????????????????????????й????????й????в??????????????????????????????????????????????????????????????????????????????????????????MSDN????????δ??size?????????????Size?????dbType??????????????С??????????????????????С?????SqlDbType??????????????????????????????????????????????????紫??????????"username"????size??8??"username1"????size??9????????????size?????????????????????????????size?????????????????????м???????????????????????sql??????????????μ???м????????????????????
???????????????????
????????????????

????DBCC FREEPROCCACHE
???????username?????????????????????????
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select * from Users where UserName=@UserName";
//??? username???????????????
//???????(@UserName varchar(8))select * from Users where UserName=@UserName
comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar) { Value = "username" });
comm.ExecuteNonQuery();
}
???????username1?????????????????????????
????????using (SqlConnection conn = new SqlConnection(connectionString))
????????{
????????conn.Open();
????????SqlCommand comm = new SqlCommand();
????????comm.Connection = conn;
????????comm.CommandText = "select * from Users where UserName=@UserName";
????????//??? username1???????????????
????????//???????(@UserName varchar(9))select * from Users where UserName=@UserName
????????comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar) { Value = "username1" });
????????comm.ExecuteNonQuery();
????????}
???????username??????????????50???????????
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select * from Users where UserName=@UserName";
//??? username??????????????50
//???????(@UserName varchar(50))select * from Users where UserName=@UserName
comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar??50) { Value = "username" });
comm.ExecuteNonQuery();
}
???username1??????????????50???????????
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select * from Users where UserName=@UserName";
//??? username1??????????????50
//???????(@UserName varchar(50))select * from Users where UserName=@UserName
comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar??50) { Value = "username1" });
comm.ExecuteNonQuery();
}