We are creating an application using WCF services that access database using Entity Framework. We are using SQL Server 2005, .Net 4.0, Entity Framework 4.0 and C#. When the WCF services are deployed, and the application starts, first database operations are always SELECT
to read some data and then, upon user interaction with the application some database updates could occur. The problem observed is with the first database UPDATE
operation performed after the services are deployed, that normally fails with the error:
An error occurred while updating the entries.
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
This error raises in the SaveChanges()
method and normally this method is enclosed in a transaction like:
// TransactionScopeOption.RequiresNew, IsolationLevel.ReadCommitted, Timeout = TimeSpan.FromMinutes(1)
using (TransactionScope scope = TransactionScopeUtil.CreateTransactionScope())
{
using (var dbcontext = new DBCtx("connectionstring"))
{
dbcontext.Connection.Open();
// Read and update database.
dbcontext.SaveChanges();
dbcontext.Connection.Close();
}
}
scope.Complete();
This very first database update operation normally fails and then never fail again until services are re-deployed.
Could be a problem with the database connection pool in the cold start?
We are not comfortable with the solution/workaround of increasing the connection/commmand timeout as could mask performance problems in the future and database updates are normally not "big".