Query with Parameter causing timeout

Asked

Viewed 68 times

2

I have a query that when running with ADO.NET it takes less than a second to return your data. When adding Parameters to this query, the return remains the same.

However, when adding a type parameter datetime, query is not executed, giving timeout error.

The parameter is being defined according to code below;

var dataInicioparameter = command.CreateParameter();
dataInicioparameter.ParameterName = "@dataInicio";
dataInicioparameter.Value = dataInicio;
dataInicioparameter.DbType = DbType.DateTime;
command.Parameters.Add(dataInicioparameter);

Consultation

SELECT * FROM 
        (SELECT *, ROW_NUMBER() OVER (ORDER BY chave) AS RowNumber1 FROM TabelaX 
               WHERE DataUltimaAtualizacao >= @dataInicio AND DataUltimaAtualizacao <= @dataFim) AS TabelaY
               WHERE RowNumber1 > (@rows * 1000) AND RowNumber1 <=  ((@rows * 1000) + 1000)
  • @Marconi edition held in the post

  • I see no problem with your query. Try to define the type first, before placing the value. What is the input value? The bank does not generate any errors other than timeout?

  • There is no problem with the query. It is executed if the date parameters are entered hard-coded. Other parameters also work correctly, the problem is when adding the date parameter. And the exception raised is timeout, with no additional information =/

  • Did you set the date as well? Because your code is only showing to start.

  • It was defined, removed from the code to not be extended

1 answer

0

Try to use SqlDbType.DateTime instead of DbType.DateTime.

var dataInicioparameter = new SqlParameter("@dataInicio", SqlDbType.DateTime) 
{ 
    Value = dataInicio;                              
};

command.Parameters.Add(dataInicioparameter);

Take a look and see this link which explains what may be causing this error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.