[英]Timeout expired while running INSERT INTO SQL statement
I want to insert data using SQL INSERT INTO statement, but an error Timeout expired occur. 我想使用SQL INSERT INTO语句插入数据,但是发生超时超时错误。 Anybody can help me.
任何人都可以帮助我。 Thanxs.
谢谢。 The code are like this.
代码是这样的。
SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["IMS"].ConnectionString);
SqlCommand sqlCom = new SqlCommand();
sqlCom = sqlConn.CreateCommand();
var strField = new List<string>();
var strVal = new List<string>();
if (this.Row.TriggerEntityID != null)
{
sqlCom.Parameters.AddWithValue("@EntityId", this.Row.TriggerEntityID);
strField.Add("EntityID");
strVal.Add("@EntityId");
}
if (this.Row.TriggerProjectID != null)
{
sqlCom.Parameters.AddWithValue("@ProjectId", this.Row.TriggerProjectID);
strField.Add("ProjectID");
strVal.Add("@ProjectId");
}
sqlCom.Parameters.AddWithValue("@EngagementId", this.Row.Id);
string[] arrField = strField.ToArray();
string[] arrVal = strVal.ToArray();
string fld = arrField[0];
string val = arrVal[0];
for (var j = 1; j < arrField.Length; j++)
{
fld = fld + "," + arrField[j];
val = val + "," + arrVal[j];
}
sqlCom.CommandText = "INSERT INTO Engagement_Project_Entity (EngagementID, " + fld + ") VALUES (@EngagementId, " + val + ")";
sqlConn.Open();
sqlCom.ExecuteNonQuery();
sqlConn.Close();
Am I missing something? 我想念什么吗? or the sequence is wrong?
还是顺序错误?
If you got a timeout exception during a query execution, that clearly shows that your C# code managed to pass the query over to the database and the database tried executing the query, but it couldn't complete the execution before the timeout. 如果在查询执行期间遇到超时异常,则清楚地表明您的C#代码成功将查询传递给数据库,并且数据库尝试执行查询,但是在超时之前无法完成执行。
So here are few troubleshooting steps I would take. 因此,这里有一些我将要采取的故障排除步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.