I have a C# ASP.NET MVC program which runs a stored procedure while loading a page. If I run the stored procedure from Microsoft SQL Server Management Studio, it takes 1 minute. However, if I try to run the same stored procedure from code, it times out. I have added Connection Timeout=0 in web.config, but sometimes it works, sometimes not.
-
1Try to set the Connection Timeout=0; in connectionString of your web.config filesri harsha– sri harsha2018-12-31 12:00:20 +00:00Commented Dec 31, 2018 at 12:00
-
I have added Connection Timeout=0 in web.config, but sometimes it works, sometimes not.user7094635– user70946352019-01-01 11:48:13 +00:00Commented Jan 1, 2019 at 11:48
Add a comment
|
1 Answer
You can set the Timeout Command to 0 when you are calling stored procedure.
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand cmd= new SqlCommand(queryString, connection);
// Setting command timeout to 0 second
cmd.CommandTimeout = 0;
try
{
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
// log ex here
}
}