I think that I'm experiencing a database connection timeout with my SQLite connection, but I'm not sure how to bump up the connection timeout. The command timeout can be set with ConnectionString.DefaultTimeout but Connection.ConnectionTimout is read only. Any suggestions?
Thanks, Brian
You can set the amount of time a connection waits to time out by using the Connect Timeout or Connection Timeout keywords in the connection string. A value of 0 indicates no limit, and should be avoided in a ConnectionString because an attempt to connect waits indefinitely.
Using SQL Server Management Studio Connect to MS SQL server via SQL Management Studio. In Object Explorer, right-click on the server name and then select Properties. In the new tab, click on Connections node. In Remote Query Timeout change it to your desired value or specify 0 to set no limit.
I had both the connection string with Default Command Timeout=300000 and the CommandTimeout set to 180. When I removed the Default Command Timeout from the connection string, it worked. So the answer is to manually set the CommandTimeout in your repository on your context object like so: this.
Exceeding the default (30 seconds) timeout for SQLite queries is a strong indication that something is wrong in your approach.
Timeouts usually occur when there are too many concurrent connections. SQLite behaves poorly when you have interleaved write/read transactions.
Make sure that you chunk related SQL statements in a single transaction (the performance gains can be x1000!).
Another tip: by default - when you start a transaction (BeginTransaction) - the default behavior is to get a write lock immediatly. Try to use BeginTransaction(deffered) version instead and specify that you want to defer acquiring a write lock until it is actually needed. This will help you if have multiple readers because now they will be able to run concurrently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With