22

I have a SQL Server [2012 Express with Advanced Services] database, with not much in it. I'm developing an application using EF Code First, and since my model is still in a state of flux, the database is getting dropped and re-created several times per day.

This morning, my application failed to connect to the database the first time I ran it. On investigation, it seems that the database is in "Recovery Pending" mode.

Looking in the event log, I can see that SQL Server has logged:

Starting up database (my database)

...roughly twice per second all night long. (The event log filled up, so I can't see beyond yesterday evening).

Those "information" log entries stop at about 6am this morning, and are immediately followed by an "error" log entry saying:

There is insufficient memory in resource pool 'internal' to run this query

What the heck happened to my database?

Note: it's just possible that I left my web application running in "debug" mode overnight - although without anyone "driving" it I can't imagine that there would be much database traffic, if any.

It's also worth mentioning that I have a full-text catalog in the database (though as I say, there's hardly any actual content in the DB at present).

I have to say, this is worrying - I would not be happy if this were to happen to my production database!

4

3 に答える 3

26

With AUTO_CLOSE ON the database will be closed as soon as there are no connections to it, and re-open (run recovery, albeit a fast paced one) every time a connection is established to it. So you were seeing the message because every 2 second your application would connect to the database. You probably always had this behavior and never noticed before. Now that your database crashed, you investigated the log and discovered this problem. While is good that now you know and will likely fix it, this does not address you real problem, namely the availability of the database.

So now you have a database that won't come out of recovery, what do you do? You restore from you last backup and apply your disaster recovery plan. Really, that's all there is to it. And there is no alternative.

If you want to understand why the crash happened (it can be any of about 1 myriad reasons...) then you need to contact CSS (Product Support). They have the means to guide you through investigation.

于 2012-08-22T12:19:17.850 に答える
21

If you wanted to turn off this message in event log. Just goto SQL Server Management Studio,

  1. Right click on your database
  2. Select Options (from left panel)
  3. Look into "Automatic" section, and change "Auto Close" to "False"
  4. Click okay

That's All :)

于 2014-10-03T18:53:05.680 に答える
2

I had a similar problem with a sql express database stuck in recovery. After investigating the log it transpired that the database was starting up every couple of minutes. Running the script

select name, state_desc, is_auto_close_on from sys.databases where name = 'mydb'

revealed that auto close was set to on.

So it appears that the database is in always in recovery but is actually coming online for a brief second before going offline again because there are no client connections.

I solved this with following script.

Declare @state varchar(20)
while 1=1
   begin
     Select @state = state_desc from sys.databases where name='mydb';
     If @state = 'ONLINE'
        Begin
           Alter database MyDb
                 Set AUTO_CLOSE_OFF;
           Print 'Online'
           break;
        End
        waitfor delay '00:00:02'
   end
于 2013-08-01T07:29:20.580 に答える