Click here to Skip to main content
16,022,054 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I know if this error occures we need to set time out to be unlimited or 5min like that but. In my scenario when run this query in ssms window it takes only 1 sec to run but when i use ado.net it throw this error if someone faced it before please suggest the solution

What I have tried:

using (SqlCommand command = new SqlCommand(query, connection))
{


connection.Open();
command.CommandTimeout = 500;
    object result =command.ExecuteScalar();---error getting here

    model.StringID = result!=null? result.ToString():null;
    connection.Close();

    return model;
}
Posted

1 solution

We can't tell because we have no access to your command, or to your DB.

Start by using the debugger to establish exactly what query contains when your code executes, and copy that exact string into SSMS.

Then check that both bits of software are connected to the same database using the same database engine, on the same computers, using the same login information.

If you still get a disparity with all of that identical, add Stopwatch code to your using block to check the exact time each part takes - look for the actual bottle neck (which may be the Open, the ExecuteScalar, the ToString, or even the Close) before trying to work out where it's really slow.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900