Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The transaction log for database is full due to 'LOG_BACKUP'" in a shared host

I have an Asp.Net MVC 5 website with EntityFramework codefirst approach in a shared hosting plan. It uses the open source WebbsitePanel for control panel and its SQL Server panel is somewhat limited. Today when I wanted to edit the database, I encountered this error:

The transaction log for database 'db_name' is full due to 'LOG_BACKUP' 

I searched around and found a lot of related answers like this and this or this but the problem is they suggest running a query on the database. I tried running

db.Database.ExecuteSqlCommand("ALTER DATABASE db_name SET RECOVERY SIMPLE;"); 

with the visual studio (on the HomeController) but I get the following error:

System.Data.SqlClient.SqlException: ALTER DATABASE statement not allowed within multi-statement transaction. 

How can I solve my problem? Should I contact the support team (which is a little poor for my host) or can I solve this myself?

like image 350
Alireza Noori Avatar asked Jan 20 '14 07:01

Alireza Noori


People also ask

How do I reduce the transaction log size?

Shrink log file size To reduce the physical size of a physical log file, you must shrink the log file. This is useful when you know that a transaction log file contains unused space. You can shrink a log file only while the database is online, and at least one virtual log file (VLF) is free.

How do I shrink a SQL server log file?

To shrink a data or log file. In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases and then right-click the database that you want to shrink. Point to Tasks, point to Shrink, and then select Files.


2 Answers

In Addition to Ben's Answer, You can try Below Queries as per your need

USE {database-name};   GO   -- Truncate the log by changing the database recovery model to SIMPLE.   ALTER DATABASE {database-name} SET RECOVERY SIMPLE;   GO   -- Shrink the truncated log file to 1 MB.   DBCC SHRINKFILE ({database-file-name}, 1);   GO   -- Reset the database recovery model.   ALTER DATABASE {database-name} SET RECOVERY FULL;   GO  

Update Credit @cema-sp

To find database file names use below query

select * from sys.database_files; 
like image 106
Mohit Dharmadhikari Avatar answered Oct 04 '22 00:10

Mohit Dharmadhikari


Call your hosting company and either have them set up regular log backups or set the recovery model to simple. I'm sure you know what informs the choice, but I'll be explicit anyway. Set the recovery model to full if you need the ability to restore to an arbitrary point in time. Either way the database is misconfigured as is.

like image 33
Ben Thul Avatar answered Oct 03 '22 22:10

Ben Thul