Deleting a Mailbox Store

Deleting a Mailbox Store

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The code in the following example deletes a mailbox store in a storage group. The subroutine searches the server for the specified storage group from which to delete the mailbox store. The delete request will fail if the mailbox store still contains mailboxes.

Visual Basic

'//////////////////////////////////////////////////////////////////////////////////
'// Name:       DeleteMailboxStoreDB
'// Purpose:    To delete a Mailbox Store (MDB)
'// Input:      strMDBName = contains the name of the MDB to be deleted
'//             strSGName = contains the name of the storage group that contains the MDB
'//             strComputerName = contains the name of the Exchange 2000 server
'//
'// Notes:      Dismount is performed automatically when deleted.
'//
'//////////////////////////////////////////////////////////////////////////////////

Public Sub DeleteMailboxStoreDB(ByVal strMDBName As String, _
                                     ByVal strSGName As String, _
                                     ByVal strComputerName As String)


    Dim iServer         As New CDOEXM.ExchangeServer
    Dim iMDB            As New CDOEXM.MailboxStoreDB
    Dim arrStGroup()
    Dim i               As Integer
    Dim strTemp         As String
    Dim strMDBUrl       As String


    ' Bind to the Exchange Server
    iServer.DataSource.Open strComputerName

    ' Build the first part of the URL to the MailboxStoreDB
    strTemp = "LDAP://" & iServer.DirectoryServer & "/" & "cn=" & strMDBName & ","

    ' Set variant array to the ExchangeServer.StorageGroups
    arrStGroup = iServer.StorageGroups

    ' Look in the StorageGroups array if the StorageGroup with strSGName exists
    If strSGName = "" Then
        ' Add last part to the URL to the MailboxStoreDB
        strMDBUrl = strTemp & iServer.StorageGroups(0)
    Else
        For i = 0 To UBound(arrStGroup)
            If InStr(1, UCase(arrStGroup(i)), UCase(strSGName)) <> 0 Then
                strMDBUrl = arrStGroup(i)
            End If
        Next
        If strMDBUrl <> "" Then
            ' Add last part to the URL to the MailboxStoreDB
            strMDBUrl = strTemp & strMDBUrl
        End If
    End If

    ' Bind to the MailboxStoreDB
    iMDB.DataSource.Open strMDBUrl  ', , , adCreateOverwrite

    ' Delete the MailboxStoreDB
    iMDB.DataSource.Delete

    ' Cleanup
    Set iServer = Nothing
    Set iMDB = Nothing

End Sub

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.