Reputation: 1
I want to insert data using SQL INSERT INTO statement, but an error Timeout expired occur. 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?
Upvotes: 0
Views: 7347
Reputation: 485
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.
So here are few troubleshooting steps I would take.
Upvotes: 1