Creating a Mailbox Store

Creating 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 creates a mailbox store in a storage group. Note that when you are creating a mailbox store, you must specify a public store. For more information, see Managing Exchange Server.

Visual Basic

'//////////////////////////////////////////////////////////////////////////////////
'// Name:       CreateNewMailboxStoreDB
'// Purpose:    To create a new Mailbox Store (MDB) with a given name
'// Input:      strMDBName = contains the name of the new MDB to be created
'//             blnMount = True if the new MDB will be mounted after creation or False
'//             if the new MDB will not be mounted
'//             strComputerName = contains the name of the Exchange 2000 server
'//             strSGName (Optional) = contains the name of the storage group to create
'//             the new MDB in; if it is empty then the new MDB will be created in the
'//             default Storage Group
'//             strMDBUrl (Optional ByRef) = contains the URL to the new MDB created;
'//
'//////////////////////////////////////////////////////////////////////////////////

Public Sub CreateNewMailboxStoreDB(ByVal strMDBName As String, _
                                        ByVal strComputerName As String, _
                                        Optional ByVal blnMount As Boolean, _
                                        Optional ByVal strSGName As String, _
                                        Optional ByRef strMDBUrl As String)

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


    ' Set the name of the MailboxStoreDB
    iMDB.Name = strMDBName

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

    ' Start to build the URL to the MailboxStoreDB - first part
    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
        ' Finish to build the URL to the MailboxStoreDB - add last part
        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
            ' Finish to build the URL to the MailboxStoreDB - add last part
            strMDBUrl = strTemp & strMDBUrl
        End If
    End If

    ' Save the New MailboxStoreDB
    iMDB.DataSource.SaveTo strMDBUrl

    ' Mount the MailboxStoreDB if blnMount is True
    If blnMount = True Then
        iMDB.Mount
    End If

    ' 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.