Errors in Shrinking the Transaction Log

Hello all,

I've been phasing a problem with my SQL Server for the last 4 months.
The transaction logs of all of my databases keep expanding enormously.
Right now one of my T-LOG files is 30 Giga and its just a small site with a few users
every day. I'm wondering what I'm I doing wrong or if I misconfigured something.

I'm trying to shrink my transaction log files using the following command, but I'm getting errors:

use dbxxx;
go
DBCC SHRINKFILE (dbxxx_Log, 1000);
GO


Here are the errors:

Msg 8985, Level 16, State 1, Line 1
Could not locate file 'dbxxx_Log' for database 'dbxxx' in sys.database_files. The file either does not exist, or was dropped.


I'm sure that the particular transaction log name is the one used by the database.

Any ideas?

Thanks
LVL 1
nectarios777Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashok KumarCommented:
use dbxxx;
go

declare @sysfilename varchar(255)
select @sysfilename =  rtrim(name) from sysfiles where fileid =2
BACKUP LOG dbxxx WITH TRUNCATE_ONLY
DBCC SHRINKFILE(@sysfilename , 1)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nectarios777Author Commented:
Hello,

here is what I get after I execute the code above:

Msg 911, Level 16, State 10, Line 4
Could not locate entry in sysdatabases for database 'test_log'. No entry found with that name. Make sure that the name is entered correctly.
Msg 3013, Level 16, State 1, Line 4
BACKUP LOG is terminating abnormally.
Cannot shrink log file 2 (dbIAGBS_Log) because all logical log files are in use.

(1 row(s) affected)
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
0
nectarios777Author Commented:
use DATABASENAME;
go


declare @sysfilename varchar(255)
select @sysfilename =  rtrim(name) from sysfiles where fileid =2
BACKUP LOG DATABASENAME WITH TRUNCATE_ONLY
DBCC SHRINKFILE(@sysfilename , 1)
0
Ashok KumarCommented:
If the database log file size yet to reduce, then just restart sql service and then run the script. alternative way also can be to detach and attach, but hopefully not in production environment.
0
nectarios777Author Commented:
Thanks for your response.
So is there any way to set un auto-shrink to the log file in case it grows unexpectetly?

I have tried to keep its size restricted, but when it reaches the restricted size the website stops
working.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.