Tuesday, March 27, 2012

DBCC SHRINKDATABASE

Has anyone used the
"DBCC SHRINKDATABASE"
in a VB.NET project to shrink a DB.
If YES,
Please, if you dont mind, paste the code in this forum.

Tnx

Just call it from a command object and it will work. This is from memory so double check the syntax, you will need to add exception handling.

Imports System.Data.SqlClient

Dim conn as New SqlConnection(<connection string goes here>)

Dim cmd as New SqlCommand

cmd.connection = conn

cmd.commandtext = "use master"

cmd.executenonquery

cmd.commandtext = "shrink database northwind"

cmd.executenonquery

conn.close()

|||Hi,

or you use the new SMO classes introduced in SQL Server 2005, just a quick sample would be:

new Server(".").Databases["Adventureworks"].Shrink(10,ShrinkMethod.TruncateOnly);

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment