Recipe6.6.Deleting a Database


Recipe 6.6. Deleting a Database

Problem

You need to remove a database you no longer need.

Solution

Using a graphical user interface

  1. Launch the Exchange System Manager (Exchange System Manager.msc).

  2. In the left pane, expand the appropriate Administrative Groups container, and then expand the Servers container.

  3. Expand the server that contains the target database, then expand the parent SG.

  4. Right-click the target database and choose Delete.

  5. ESM will display a confirmation dialog to ask if you really want to delete the selected store. Click Yes to delete the store or No to leave it alone.

  6. ESM will display a dialog reminding you to remove the database files manually from disk. Click OK to dismiss this.

Using VBScript
' This code removes the specified mailbox database from its ' parent storage group without touching the on-disk files ' ------ SCRIPT CONFIGURATION ------  strServerName = "<serverName>"    ' e.g., "BATMAN"      strMDBName = "<mdbName>"  ' ------ END CONFIGURATION --------- Set theServer = CreateObject("CDOEXM.ExchangeServer") ' To delete a public folder database here, just change this class ref  ' to CDOEXM.PublicStoreDB Set theMDB = CreateObject("CDOEXM.MailboxStoreDB") ' bind to the Exchange server and build the database URL theServer.DataSource.Open strServerName arrSG = theServer.StorageGroups theFirstSG = arrSG(0) strURL = "LDAP://" & theServer.DirectoryServer & "/cn=" & strMDBName & "," & theFirstSG theMDB.Name = strMDBName theMDB.DataSource.Open strURL theMDB.DataSource.Delete WScript.Echo "Database deleted."

Discussion

When you delete a database file, you're severing its relationship with its parent SG, as well as deleting the corresponding AD object. However, neither ESM nor CDOEXM removes the actual database files from the filesystem. This is a useful protective measure, since you can easily create a new database with the same name, dismount it, and replace its files with the original database files.

Using VBScript

The code in this script only works with mailbox databases because it uses the MailboxStoreDB object from CDOEXM. To make it work with public databases, you need to modify it to use the PublicStoreDB object instead. In either case, the code for deleting a database is similar to that used for creating a database; the difference is that you must bind to the MailboxStoreDB or PublicStoreDB object and use its Delete method to remove the database object instead of just instantiating the object and then using the SaveTo method.

See Also

Recipes Recipe 6.4 and Recipe 6.5 for creating mailbox and public folder databases



Exchange Server Cookbook
Exchange Server Cookbook: For Exchange Server 2003 and Exchange 2000 Server
ISBN: 0596007175
EAN: 2147483647
Year: 2006
Pages: 235

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net