SQL Server - How to Truncate Transaction Log in SQL2000 usin SQLDMO
Asked By Noman Nasir
20-Dec-06 02:40 AM
My Data Base log became bigger enough to 20GB I want to trancate the log using SQLDMO
I write the following code. Code is executed without error but log file size remains same.
Plz Help
Dim mServer As New SQLDMO.SQLServer2
mServer.Connect "ServerName", "UID", "PWD"
mServer.Databases.Item("DBName").TransactionLog.Truncate
Very easy way to truncate Transaction log
in SQL Server 2000
backup log [database name] with truncate_only
(run this in query analyzer)
(open enterprise manager and expand the server tree)
--right click on the database
--all task
--shrink database
--bottom button (on right side of form) for files
--select sql log file (default is data file so make sure and change it)
--click ok
the log size of my main database was 67 gigs. I ran this and it shrinked my database size from 67 gigs to 50 megs (49 of which is the data file)
reference
http://forums.databasejournal.com/archive/index.php/t-40824.html
Truncate SQL Server Transaction Log
http://www.codeproject.com/cs/database/ClearTransactionLog.asp
Thanx
use DBCC
DBCC statememnts act as Database Console commands. You can use the below listed queries, sprcifically the DBCC ones to shrink your transaction log.
-- To GET the name of the log and data files
select name from dbo.sysfiles
-- SEE the active transactions as well as the File ID
dbcc loginfo('db_Name')
-- Mark transactions inactive so that they can be truncated later
-- Suppose file ID is 2
DBCC SHRINKFILE (2)
-- Backup the log file and truncate the inactive entries
BACKUP LOG [db_name] WITH TRUNCATE_ONLY
-- Run Shrinkfile again for maintainence.
DBCC SHRINKFILE (2)
You can create a stored procedure out of the last 3 statements and schedule it as a job on your server than can run overnight and ensure that the transaction log file size does not get out of hand.
Hope this helps.
Asha replied to K Pravin Kumar Reddy
I tried to shrink database and selected the Transaction log file and saw when the process got done, the Transaction Log remained the same size. Do you have any suggestions?
Thank you
K Pravin Kumar Reddy replied to Asha

Hi Asha,
I'm not sure about SQL SERVER edition you are using, but you can try following steps..
Shrink SQL Server Log File
These instructions detail how to shrink a SQL Server Log File.
I. Shrink the log file size at the right time
Immediately after using the SSIS package or Import the data to the database ( highlight the database->Tasks->Import data … ), or Export the data from the database ( highlight the database->Tasks->Export data … ), shrink the log file to the desired size, for example, 1MB. That is, highlight the database->Tasks->Shrink->Files
set the file size, say, 1MB.
Then, click OK and you are done.
Eliminate SQL Server Log File
These steps detail how to eliminate a SQL Server Log File entirely.
II. Eliminate the log file completely
Sometimes we just do not need the big log file. The logic is
a. Detach the database
b. Rename the log file
c. Attach the database without the log file
d. Delete the log file
Let’s say, the database name is testDev. In the SQL Server Management Studio,
-
Highlight the database-> Tasks->Detach..-> Click OK
-
Go to log file folder -> rename the testDev_log.ldf to be like testDev_log-aa.ldf,
-
Highlight Databases->Attach…-> Click Add -> add the database testDev, highlight the log file and click the ‘Remove’ button. This means you only attach testDev.mdf
-
After this is done, you can verify the contents of the attached database and then delete the log file.
Fati replied to Noman Nasir
Thak you very much. I got the answer very satisfactory.

Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B)What is a objects in Remoting? (A) What are the ways in which client can create object on server in CAO model? (A) Are CAO stateful in nature? (A) To create objects in CAO implementation to Remoting Client? (A) What are LeaseTime, SponsorshipTime, RenewonCallTime and LeaseManagerPollTime? (A) Which config file has all the supported channels / protocol? (A) How can you specify remoting parameters using Config the different phase / steps of acquiring a proxy object in Web service? (B) What is file extension of Web services? (B) Which attribute is used in order that the method can dependencies in cache and types of dependencies? (A)Can you show a simple code showing file dependency in cache? (A) What is Cache Callback in Cache? (A) What is scavenging? (B page ? (I) Can we post and access view state in another application? (I) What is SQL Cache Dependency in ASP.NET 2.0? (I) How do we enable SQL Cache Dependency in ASP.NET 2.0? (I) What is Post Cache substitution? (I) Why
when you should go for them? User defined data types let you extend the base SQL Server data types by providing a descriptive name, and format to the database. Take for example type is used to store Boolean information like 1 or 0 ( true or false ). Until SQL Server 6.5 bit data type could hold either a 1 or 0 and there was no support for NULL . But from SQL Server 7.0 onwards, bit data type can represent a third state, which is NULL . Define t have defaults bound to them. See CREATE DEFAULT in books online. What is a transaction and what are ACID properties? A transaction is a logical unit of work in which, all the steps must be performed or
how to maintain log information Hello every body. I have sample table "Test" I want to maintain log information for this table whenever there is a change / entry in this table. How this can be done? Regards, SZ. The first is to custom write your own triggers to log precisely what you want. This lets you log exactly what you want exactly how you want. Of course, it can take some time scale auditing and accountability. This is a technique I have used with great success in SQL Server 2005 though. The next is 3rd party software like Idera's compliance manager ( http: / / www.idera.com / Products / SQL-Server / SQL-compliance-manager / ). I have done evaluations on them and found that for most purposes
Interview questions for 4+ years .net developer SQL Server could some one list out few good sql queries that would be asked during the interview process for a 4+ year .net developer when you should go for them? User defined data types let you extend the base SQL Server data types by providing a descriptive name, and format to the database. Take for example type is used to store Boolean information like 1 or 0 ( true or false ). Until SQL Server 6.5 bit data type could hold either a 1 or 0 and there was no support for NULL . But from SQL Server 7.0 onwards, bit data type can represent a third state, which is NULL
Can Any One provide Issues in SQL SERVER 2005 on Log Shipping. . . . . . . . Hi All, Can Any One provide Issues in SQL SERVER 2005 on Log Shipping, Mirroring, Replication, Clustering, . . . . etc., Thanks In Advance, Venki Desai. Here’s the steps that I finally found that works. Let’s assume there are 2 servers with SQL Server 2005. Make sure both servers have latest SP. There’s Service Pack 1 released already