Error Timeout ASP.NET SP

1

I have a detail when loading the StoredProcedure and fill in a datatable , I mark the error:

  

"Timeout expired The timeout period elapsed prior to completion of the operation or the server is not responding The statement has been terminated"

I already tried with ...

var conn = new SqlConnection(@"SERVER=server;DataBase=db; user=us;password=pass;Connect Timeout=120;");
SqlCommand comm = new SqlCommand("stored_procedure", conn);

and when I run the SP in SQL Server it takes 1min very long to load the info!

    
asked by Fernando 16.08.2016 в 19:31
source

2 answers

0

You have to upload the command timeout, it is different from the connection string.

Try this

SqlCommand comando = new SqlCommand();
comando.CommandTimeout = 120;
    
answered by 16.08.2016 / 19:38
source
0

As indicated by AldoRomo88 you must define the TimeOut of SQLCommand so that this works how you want (in this answer they tell it in more detail):

using (SqlCommand cmd = new SqlCommand())
{
  cmd.Connection = conn ;
  cmd.CommandTimeout = 240; //en segundos
  //etc...
}

But I would like to add that sometimes there are inconsistencies between running an SP from the SQL Server itself compared to executing it from C #. If you want to learn more about it this link tells you all about it.

In summary mode, many times this is slow due to internal SQL processes that are only executed if the SP is called from C #, to solve it, it sends this command:

UPDATE STATISTICS [TABLE NAME]
GO

EXEC sys.sp_recompile @objname = N''
GO
    
answered by 17.08.2016 в 09:27