c# - How to use try catch error for sql query timeout? -


how can use try catch if there error in connection sql query in c#?

if use simple code below work time takes error occur long. how can try catch handle error quicker?

try {   //sql command } catch {   //display connection error } 

try-catch catch exception occurs, don't except catch timeout exception before timeout occurs. sqlcommand, default timeout 30 seconds, can change setting commandtimeout property:

try {      var command = new sqlcommand("...");     command.commandtimeout = 5; // 5 seconds     command.executenonquery(); } catch(sqlexception ex) {     // handle exception... } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -