Hi @GeoJoseph ,
problem 1
A timely solution is to increase the timeout.
According to your discription, follow this: sqlcommand.CommandTimeout = 120;
The default value of SqlCommand.CommandTimeout is 30 seconds, you don't need to set 120, or you can set other suitable values.
This type of timeout can have three causes.
1.There's a deadlock somewhere
2.The database's statistics and/or query plan cache are incorrect
3.The query is too complex and needs to be tuned, which can be excluded with your description.
A deadlock can be difficult to fix, but it's easy to determine whether that is the case. Connect to your database with Sql Server Management Studio. In the left pane right-click on the server node and select Activity Monitor. Take a look at the running processes. Normally most will be idle or running. When the problem occurs you can identify any blocked process by the process state. If you right-click on the process and select details it'll show you the last query executed by the process.
The second issue will cause the database to use a sub-optimal query plan. It can be resolved by clearing the statistics: exec sp_updatestats
If that doesn't work you could also try: dbcc freeproccache
You should not do this when your server is under heavy load because it will temporarily incur a big performace hit as all stored procs and queries are recompiled when first executed.
BTW, as for the third issue, if you do a query about table, you should better create a index on it for better performance.
problem 2
The connection is automatically disconnected because the database has not been operated for too long.
You can reconnect after the link is broken, which is a fault-tolerant method of the program.
Best regards,
Seeya
If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.