Search code examples
sql-serverentity-frameworkiisinitializer

EF drops Database after some inactivity


I'm using ASP.NET Web API with EF 6 (Code First) and for development purpose I created an initializer with a DropCreateDatabaseAlways.

I deploy the application on a remote server (IIS 8.0) and I noticed that after some inactivity, when a call is made on the API, the initializer is called. I thought this initializer only drops and creates the database on each run of the application, but once deployed the application doesn't stop to run, so is there any timeout, or something like this ?

If you have any ideas why is it happening.

Here is some code and logs to help. The Context :

public MyDAL()
        : base("MyEntities")
    {
        Database.SetInitializer<MyDAL>(new MyInitializer());
        this.Database.Log = s => log.Info(s);
    }

Some logs :

// At 05:30 the request is successful without droping/creating the database 2014-12-28 05:30:38,312 INFO - -- Executing at 28/12/2014 05:30:38 +01:00

2014-12-28 05:30:38,343 INFO - -- Completed in 27 ms with result: SqlDataReader

2014-12-28 05:30:38,343 INFO -

2014-12-28 05:30:38,343 INFO - Closed connection at 28/12/2014 05:30:38 +01:00

// At 06:46 A client asks for the Authentication Service 2014-12-28 06:46:15,398 INFO - 2014-12-28 06:46:21,070 INFO - Opened connection at 28/12/2014 06:46:21 +01:00

2014-12-28 06:46:21,132 INFO - Started transaction at 28/12/2014 06:46:21 +01:00

2014-12-28 06:46:21,132 INFO - CREATE TABLE [dbo]...


Solution

  • So, it seems to be that, the problem was the configuration of the application pool in IIS. The Idle time-out was set before at 20 minutes and now with the timeout set at 24h, the problem disappeared.