Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set ConnectionTimeout in System.Data.SQLite

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

like image 922
Brian Sweeney Avatar asked Jul 24 '09 00:07

Brian Sweeney


People also ask

How do I set connection timeout?

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.

How do I change the connection timeout in SQL?

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.

How do I set the execution timeout in Entity Framework?

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.


1 Answers

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.

like image 109
Liron Levi Avatar answered Sep 26 '22 13:09

Liron Levi