Truncate Transaction Log Script Won't Work On Db Name With '-'
Feb 25, 2008
Hello all, I have a very simple script which I use to truncate and reclaim space on all the transaction logs in a SQL Server 2005 database. However, I have some Sharepoint db names I can't change that have dashes ('-') in the names, e.g., SharePoint_AdminContent_dc27334f-fb2d-4453-9764-5d8b730fb9e1. The script won't back up those databases because it has a problem with the dashes in the names. Does anyone have any thoughts on how I could modify the script to get it to work? Here is the script:
ALTER PROCEDURE [dbo].[SP_GlobalTruncate_transaction_logs]
AS
Set quoted_identifier off
DECLARE @dataname varchar(300)
DECLARE @dataname_header varchar(75)
DECLARE datanames_cursor CURSOR FOR SELECT name FROM sysdatabases
WHERE name not in ('master', 'pubs', 'tempdb', 'model', 'northwind')
OPEN datanames_cursor
FETCH NEXT FROM datanames_cursor INTO @dataname
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status = -2)
BEGIN
FETCH NEXT FROM datanames_cursor INTO @dataname
CONTINUE
END
SELECT @dataname_header = 'Database ' + RTRIM(UPPER(@dataname))
PRINT ' '
PRINT @dataname_header
EXEC('BACKUP LOG ' + @dataname + ' WITH TRUNCATE_ONLY')
EXEC('DBCC SHRINKDATABASE (' + @dataname + ',TRUNCATEONLY)')
FETCH NEXT FROM datanames_cursor INTO @dataname
END
DEALLOCATE datanames_cursor
PRINT ''
PRINT ' '
PRINT 'Free space removed and transaction log truncated for each user database'
GO
And here is the error I get:
Database SHAREPOINT_ADMINCONTENT_DC27334F-FB2D-4453-9764-5D8B730FB9E1
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.
Msg 319, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.
Thanks so much for the help.
View 4 Replies
ADVERTISEMENT
Aug 8, 2000
I have been unsuccessful in getting the Backup Log with
No Truncate option to work.
Any tips, tricks, suggestions, etc., would be appreciated.
Thanks!!!
View 2 Replies
View Related
Nov 13, 2007
I've been having some trouble keeping my log file size under control due to some off-hours data loads. Currently, while updating some certain tables, the data base is still in "Full" mode, which of course makes the log file grow accordingly.
Today I figured out that, given the current scenario, in order to shrink the log file back down (after the table update), I have to (1) backup the log file, (2) shrink the log file, (3) backup the log file again, and (4) shrink the log file again. My question is: why do I have to do two iterations of backup / shrink? Why does it not work with one iteration? I just want to better understand the architecture and functionality.
Also, would there be a better way for keeping the log file size under control? If I switched the database to "Simple" mode to load the data, would that work any better?
If so, what might be the best methodology?
Thanks in advance for any responses.
Kent Rothrock
Highland Mapping, Inc.
View 4 Replies
View Related
Aug 2, 2000
hi,
I have a stored procedure to calculate the balance for a group of people. Inside the sp,
I created a temp table at the beginning of the procedure, then use it to calculate the opening
balance first, then I truncated the table in the middle, reuse it to calculate the closing balance.
The sp will take the from date and the through date to do the calculation. Somehow,
when I passed a different from date and the same through date to the sp, it returned a different
closing balance. It took me a while to figure out that the temp table I was using didn't get
truncated in the middle. I did a 'select count(*) ' directly after the truncate statement.
Sometimes it returned a non-zero number, and sometimes it returned 0.
We are using SQL 7.0 Service pack 1. Does anyone know the reason?
Heidi Zhang
hZhangcti@use.net
View 3 Replies
View Related
Oct 7, 1999
Hello,
We have a SQL 6.5 Server with several DB's on it. Specially there's a critical DB on two separate devices for the Data and Transaction Log. The Data Device is 700MB and the Transaction Log started 210MB. Yet, the truncate function of the Log Device is not freeing space on it. We have been forced to expand the transaction device up to 860MB!!!! which is an outrageous size for it. We have tried the DBCC CHECKTABLE(syslogs)followed by DUMP TRANSACTION <<db_name>> WITH NO_LOG and then once again the DBCC CHECKTABLE(syslogs).
We even tried to create a new DB only with the dat file, but this also didn't work. Our Server Disks are almost full, and we can't grow the device no more.
Any suggestions??? PLEASE IT's REALLY URGENT!!!!
Best Regards,
BIT CeLA
Pfizer Labs.
Colombia
View 4 Replies
View Related
Feb 6, 2002
How do you truncate the transaction log in SQL 2000?
View 1 Replies
View Related
Feb 13, 2002
I need to truncate the transaction log, however, to do a backup on it we need 15GB of space free on the server which we don't have. How do we just force it to truncate it? I know the actual database is backedup and is OK...
Thanks,
Keith
View 1 Replies
View Related
Aug 1, 2001
SQL Server 6.5
Hi!
We have trans.log 200MB in total and 71 MB free space.
I run DBCC OPENTRAN and it shows no active transactions exist.
I run DuMP TRANSACTION .... WITH TRUNCATE_ONLY and it doesny clean log also.
What to do to get space back?
Thank you,
Elena.
View 4 Replies
View Related
Oct 17, 2001
SQL Server 6.5
NT
A number of procedures where run that filled the transaction log. Can I truncate the log during regular working hours or should I take the database down to single user mode and truncate?
Thanks in advance..
View 4 Replies
View Related
Feb 19, 2004
Hi all,
please show me the way how to truncate transaction log.
thank alot
View 2 Replies
View Related
Feb 27, 2004
DB Newbie question ahead.
I have a mere 100MB db with a 4GB transaction log. I want to truncate the log as I understand that truncating it will shrink the log by removing the transactions that have already taken place. However, the option to do a transaction backup is greyed out. I suspect this is from the db being in transactional replication with another server; however, I don't know for sure.
Are there any other ways that I can shrink the transaction log? I would like to do shrink it without taking the db offline either.
View 3 Replies
View Related
Dec 11, 2007
Hi
I need a simple command to truncate my transaction log. Currently it is 4gb and my .mdf file is only 300mb.
I have tried BOL, but all I need is a command to truncate it.
Thanks!
View 3 Replies
View Related
Dec 11, 2007
We do full backup every day and recovery model is Full, but we never done transaction log backup, so the transaction log files keep growing. What should I do? I think I should set recovery model to Simple, and actually we do DBCC Shrinkdatabase after full backup every day, but the transaction log file is still around 15GB.
Any suggestion would be appreciated.
View 9 Replies
View Related
Aug 12, 1998
Hi all,
Is it possible to TRUNCATE a table and BCP data into the same table in one
TRANSACTION?
My problem is that I want to refresh(delete and via BCP append new data) a
table without disturbing running applications. Can I run BCP from a
SQL-script or a stored procedure?
Thank`s
Jonas Dahlqvist
Alfa Laval Automation AB
View 1 Replies
View Related
Jan 27, 2005
Hello;
Within SQL Ent Manager - I am unable to truncate the tran log using the shrink file option window (although I can shrink the database file) - nor can can I truncate the log using command line sql in a query analzer window (dump tran < > with truncate only)....
Anyone out there offer any suggestions??
Thanks.
View 4 Replies
View Related
Dec 29, 2007
I use SSME to do a full backup of both the database & transaction log, selected "Truncate ..." in the options for the log backup. The log doesn't truncate.
I have looked at the reasons logs don't truncate in Books Online & can not find any that apply. There are no open transactions & in sys.databases log_reuse_wait is 0.
Any help would be appreciated.
Don Seydel
View 1 Replies
View Related
Oct 20, 2005
Hi guys
My website is in asp and sql2000. My problem is the ISP gave access to database through query analyser. some days the transaction log is growing too high. so i want to clear it. i call up them and clear it. My question is can truncate the log file through query analyser ?
I had limited access to database.
Jini
View 11 Replies
View Related
Mar 6, 2007
friend can i ask something like this
what query that can i truncate the transaction logs or shrink it into
2mb.
Please response to this. I need help
Thanks
View 7 Replies
View Related
Aug 28, 2007
Is it possible to truncate Transaction Log and Shrink DATABASE while the database is being used by users or the database becomes unuvailable during this operations?
Thank you.
View 2 Replies
View Related
Feb 9, 2015
SQL 2012 Ent SP2
Database is in simple recovery mode, and published with transaction replication push subscription, just one subscriber but the database is huge. I don't want to overwrite the schema at the subscriber either.
I had to run an alter database command on a published database, it created so many logs that an extra drive had to be added along with an extra log file to accommodate all the logs.
The problem I have is I'd like to know clear the file of logs so I can drop the temporary log file, and give the drive back, but I cannot.
I have tried dbcc shrinkfile with the emptyfile option but it never clears, I have also tried it with notruncate and truncateonly options (mainly out of desperation).
I do not need to worry about point in time restore as a full backup is taken before and after the operation. After which the database will be put back into Full recovery mode.
I have looked at log_reuse_wait_desc and the file says 'Replication', so I am now thinking the file cannot empty because replication is keeping one of the VLFs active. I tried dropping and recreating the subscription hoping it might free something up and I could get somewhere, but it made no difference.
Do I have to remove replication completely to get round this? Surely not.
I have also tried putting the database back into full recovery mode, doing a full DB backup, and a transaction log backup, but its made no difference, which is also what makes me think a portion of the log is still active because of replication, and perhaps the transactions have not gone through to the subscriber, which raises another question, why not?
I have not tried restarting SQL server, as I'd like to know a way out of this without having to do that, plus I do not think it would make any difference anyway.
View 1 Replies
View Related
Oct 3, 2007
I created transactional replication on a database and setup pull subscriptions on each subscriber to run at a scheduled time once a day. The scheduled start time on each subscriber can differ. The transaction log on the publishing database will eventually consume all possible disk space. Is it possible (and safe) to shrink or truncate the transaction log file for the publishing database before all the subscribers completed running its daily pull subscription? If not, how can I manage disk space for the transaction log on the publishing database and ensure all transaction are replicated to the subscriber?
Thanks in advance.
View 1 Replies
View Related
Aug 18, 2015
We have a SQL server 2012 database with size 200mb and Transaction Log has gone up to 34GB.
We have SQL server Mirror is enabled and principal database is running with Full Recovery Model.
How can I truncate/Shrink Log files? Will it impact on existing mirroring setup? I am very much new to SQL server.
View 17 Replies
View Related
Jun 28, 2007
Hi,
I have one database configured with the Recovery Model "Simple".
I am getting alot of full transaction log messages... is this supposed to happen?
Another question is:
Imagine i am in a middle of a big select into statement... and in another query i run the backup truncate log... am i going to loose information on the other batch ("select into?")??
Kind Regards,
Luis Simões
View 5 Replies
View Related
May 15, 2006
We are using SQL Server 2005 (SP1). I have created a maintenance plan that backs up up the datebase every night. The problem is that the transaction log is continuing to grow. I have been told that a full backup will automatically truncate and shrink the transaction log. However, this is not happening. How can I truncate and shrink the transaction log after a full backup as part of our maintenance plan. Thank you.
View 29 Replies
View Related
Jan 3, 2006
I am having some problems wit a form where i need to insert a record into a table and then get the id of the record i just inserted and use it to insert a record in another table for a many to many relationship. The code is below (I cut out as much as i could to make it more readable).
The erro message i get is this:
Error saving file ATLPIXOFC.txt Reason: System.Data.SqlClient.SqlException: Prepared statement '(@FileName varchar(13),@ i' expects parameter @FileID, which was not supplied. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microvit_Document_Product_Document_Add_v2.insertDocumentToDB() in e:inetpubwwwrootMicrovitDocumentProduct_Document_Add_v2.aspx.vb:line 127 at Microvit_Document_Product_Document_Add_v2.btnInsert_Click(Object sender, EventArgs e) in e:inetpubwwwrootMicrovitDocumentProduct_Document_Add_v2.aspx.vb:line 37
Protected Sub insertDocumentToDB()
Dim myConnString As String = ConfigurationManager.ConnectionStrings("Master_DataConnectionString").ConnectionString
Dim myConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(myConnString)
Dim myCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
Dim myTransaction As System.Data.IDbTransaction = Nothing
myCommand.Connection = myConnection
myCommand.Parameters.Add(New SqlParameter("@FileName", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@ProductID", SqlDbType.Int))
myCommand.Parameters.Add(New SqlParameter("@FileID", SqlDbType.Int, ParameterDirection.Output))
myCommand.Parameters("@FileName").Value = fuDocument.FileName
myCommand.Parameters("@ProductID").Value = ddlProduct.SelectedValue
Try
'****************************************************************************
' BeginTransaction() Requires Open Connection
'****************************************************************************
myConnection.Open()
myTransaction = myConnection.BeginTransaction()
'****************************************************************************
' Assign Transaction to Command
'****************************************************************************
myCommand.Transaction = myTransaction
'****************************************************************************
' Execute 1st Command
'****************************************************************************
myCommand.CommandText = "INSERT INTO [Files] ([FileName) VALUES (@FileName); SELECT @FileID = @@Identity;"
myCommand.ExecuteNonQuery()
'****************************************************************************
' Execute 2nd Command
'****************************************************************************
'myCommand.Parameters("@FileID").Value = ddlProduct.SelectedValue
myCommand.CommandText = "INSERT INTO [ProductFiles] ([ProductID], [FileID]) VALUES (@ProductID, @FileID)"
myCommand.ExecuteNonQuery()
myTransaction.Commit()
Catch
myTransaction.Rollback()
Throw
Finally
myConnection.Close()
End Try
End Sub
View 3 Replies
View Related
Sep 27, 2007
Could somebody also help me on the issue: I am using OLE DB to setup database with SQL CE 3.1, what i need is to flush the buffer to database file before program exit, I am using DBPROPVAL_SSCE_TCM_FLUSH and Transaction commit, but they don't work for me, My code is here:
1. the code to do transaction commit
// Access Transaction Interface
hr = pIDBCreateCommand->QueryInterface(IID_ITransactionLocal, (void **) &pTransLocal);
ULONG lTransLevel;
// Start the transaction
hr = pTransLocal->StartTransaction( ISOLATIONLEVEL_READCOMMITTED, 0, NULL, &lTransLevel );
// Execute the command with paramters.
hr = pICommandText->Execute(NULL, IID_NULL, ¶ms, &cRowsAffected, NULL);
if( FAILED( hr ) )
{
goto Exit;
}
// commit
hr = pTransLocal->Commit( FALSE, XACTTC_SYNC, 0 );
pTransLocal->Release();
2. the code to set up property:
void LogDatabase::SetSessionProperty( IDBCreateSession *pISession )
{
DBPROPSET dbpropset[1]; // Property Set used to initialize provider
DBPROP sessionProps[1];
VariantInit(&sessionProps[0].vValue);
ISessionProperties *pISessionProperties = NULL;
//************** We Initial a session properties here *************
// Initialize a session object.
HRESULT hr = pISession->CreateSession(NULL, IID_ISessionProperties,
(IUnknown**) &pISessionProperties);
// Initialize the property to change commit mode.
sessionProps[0].dwPropertyID = DBPROP_SSCE_TRANSACTION_COMMIT_MODE;
sessionProps[0].dwOptions = DBPROPOPTIONS_REQUIRED;
sessionProps[0].vValue.vt = VT_I4;
sessionProps[0].vValue.lVal = DBPROPVAL_SSCE_TCM_FLUSH;
// Initialize the session property set.
dbpropset[0].guidPropertySet = DBPROPSET_SSCE_SESSION;
dbpropset[0].rgProperties = sessionProps;
dbpropset[0].cProperties = sizeof(sessionProps)/sizeof(sessionProps[0]);
// Set the session property.
hr = pISessionProperties->SetProperties(sizeof(dbpropset)/sizeof(dbpropset[0]),
dbpropset);
VariantClear(&sessionProps[0].vValue);
}
View 1 Replies
View Related
Oct 30, 2000
What is the best way to control Transaction log sizes?? The logs keep growing and when I manually truncate
them and use the dbcc shrinkfile command, it doesn't want to shrink it to the specified size. In some cases,
our data file is smaller than the log file. It'll have a Gig of space allocation but only contain 40 megs of data.
Any suggestions on how I can shrink the log file??
View 3 Replies
View Related
Jul 10, 2015
I have this sql stored procedure in SQL Server 2012:
ALTER PROCEDURE [dbo].[CreateBatchAndSaveExternalCodes]
@newBatches as dbo.CreateBatchList READONLY
, @productId int
, @cLevelRatio int
, @nLevelRatio int
AS
set nocount on;
[Code] ....
View 4 Replies
View Related
Dec 30, 2004
With a database size of almost 2 GB, I run the 'truncate table eventlog command' which completes successfully, but the database size only decreases by about 10 MB so stays too large - indeed the number of rows in the eventlog table is minimal, but the otehr tables in this database don't show such an amount of tables large enough to cause the size issue either. What could be the reason and how can I reduce it (possibly truncating another table but then which one, how could I determine which is too large and needs truncating?).
View 3 Replies
View Related
Apr 17, 2008
Hi all...
Please forgive the elementary nature of my question, but could someone please explain the differences between these two database backup types:
1. Log backup
2. Log backup no truncate
From what I understand and have read, the "no truncate" backup method keeps the entire transaction log indefinitely. Using the truncation method, the transaction log is either 1) compressed or 2) cleaned up so that any completed transactions are removed from the log. Which one of these is true?
And, for the big question: is it better to run a backup of the transaction log with truncation or not? Our current backup scheme is similar to the following:
Full backup every 24 hours
transaction log backup every hour with no truncation
Should we insert a truncation backup somewhere in here? What is the danger of removing (or compressing) parts of the transaction log? Will this affect the restore process?
Thanks in advance!
View 6 Replies
View Related
May 31, 2008
Hi All
I'm getting this when executing the code below. Going from W2K/SQL2k SP4 to XP/SQL2k SP4 over a dial-up link.
If I take away the begin tran and commit it works, but of course, if one statement fails I want a rollback. I'm executing this from a Delphi app, but I get the same from Qry Analyser.
I've tried both with and without the Set XACT . . ., and also tried with Set Implicit_Transactions off.
set XACT_ABORT ON
Begin distributed Tran
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.TRANSACTIONMAIN
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.TRANSACTIONMAIN
set REPFLAG = 0 where REPFLAG = 1 and DONE = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.WBENTRY
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.WBENTRY
set REPFLAG = 0 where REPFLAG = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.FIXED
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.FIXED
set REPFLAG = 0 where REPFLAG = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.ALTCHARGE
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.ALTCHARGE
set REPFLAG = 0 where REPFLAG = 1
update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.TSAUDIT
set REPFLAG = 0 where REPFLAG = 1
update TSADMIN.TSAUDIT
set REPFLAG = 0 where REPFLAG = 1
COMMIT TRAN
It's got me stumped, so any ideas gratefully received.Thx
View 1 Replies
View Related
Feb 22, 2007
I have a design a SSIS Package for ETL Process. In my package i have to read the data from the tables and then insert into the another table of same structure.
for reading the data i have write the Dynamic TSQL based on some condition and based on that it is using 25 different function to populate the data into different 25 column. Tsql returning correct data and is working fine in Enterprise manager. But in my SSIS package it show me time out ERROR.
I have increase and decrease the time to catch the error but it is still there i have tried to set 0 for commandout Properties.
if i'm using the 0 for commandtime out then i'm getting the Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.
and
Failed to open a fastload rowset for "[dbo].[P@@#$%$%%%]". Check that the object exists in the database.
Please help me it's very urgent.
View 3 Replies
View Related
Feb 6, 2007
I am getting this error :Distributed transaction completed. Either enlist this session in a new
transaction or the NULL transaction. Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code. Exception Details:
System.Data.OleDb.OleDbException: Distributed transaction completed. Either
enlist this session in a new transaction or the NULL transaction.have anybody idea?!
View 1 Replies
View Related