Skip navigation

Mounting and Dismounting Databases with CDOEXM

I spend a fair amount of time reading the Microsoft public support Exchange newsgroups, where many of the same questions are asked over and over. This year I'd like to occasionally answer some of the more obscure questions in this column. This week, I decided to start with a real winner: How do you programmatically mount and dismount Exchange Server 2003 and Exchange 2000 Server databases? This task is fairly simple, but unless you spend a lot of time spelunking in the Microsoft Developer Network (MSDN) Collaboration Data Objects for Exchange Management (CDOEXM) documentation, you might not be aware of it. Here's a short script, in pieces, that mounts a mailbox database. The first piece of code defines the server (batman) and mailbox database ("Mailbox Store (BATMAN)"). It also creates two CDOEXM objects: The ExchangeServer object is used later, and the MailboxStoreDB object is used to mount and dismount the database. strServerName = "batman" strMDBName = "Mailbox Store (BATMAN)" Set theServer = CreateObject("CDOEXM.ExchangeServer") Set theMDB = CreateObject("CDOEXM.MailboxStoreDB") The next piece of code connects to the server and finds the first storage group (SG). The StorageGroups property of the ExchangeServer object lists all the SGs on that server. VBScript doesn't have a good way to find the first item in a collection, which is why the code starts a "for each" loop, then immediately exits. theServer.DataSource.Open strServerName For Each sg In theServer.StorageGroups theFirstSG = sg Exit for Next After you have the name of the first SG, mounting the store is a simple matter of constructing a URL to the database from a combination of the SG name and the database name, then using that URL to open the message database (MDB) object. After the object is open, you can mount or dismount it using the Mount and Dismount CDOEXM methods. strURL = "LDAP://" & theServer.DirectoryServer & "/cn=" & strMDBName & "," & theFirstSG theMDB.DataSource.Open strURL theMDB.Mount This script can be improved. It doesn't perform any error checking (e.g., it'll fail if you try to mount an already-mounted database), and it doesn't work with public folder databases (you'll need to use the CDOEXM PublicStoreDB object instead). It's not terribly useful for mounting or dismounting one database at a time, so a useful enhancement would be to automatically mount or dismount multiple stores at once. These changes are all simple to make, and after you understand the mechanism you can apply it to a lot of other database-related tasks (including creating and deleting databases and moving databases and log files).

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish