Microsoft KB Archive/248106

From BetaArchive Wiki
Knowledge Base

How To Use the IDBDataSourceAdmin Interface of the Jet OLE DB Provider to Create a Blank .mdb File

Article ID: 248106

Article Last Modified on 8/30/2004


  • Microsoft OLE DB Provider for Jet 4.0
  • Microsoft OLE DB 2.1
  • Microsoft OLE DB 2.5
  • Microsoft OLE DB 2.6

This article was previously published under Q248106


The Jet OLE DB provider supports the IDBDataSourceAdmin interface, an optional OLE DB interface that is used to create, destroy, and modify data source objects. This article demonstrates how to use this interface to create an empty Microsoft Access .mdb file.


It is important to distinguish between the data source object and the data store. The data source object is the object that is used by the OLE DB consumer code. The data store is the actual physical source of data, such as a server database.

The IDBDataSourceAdmin::CreateDataSource function creates and initializes a data source object and the data store in one atomic operation. The OLE DB consumer must set any Data Source Creation or Initialization properties that are required by the provider to create and initialize the data source.

NOTE: If you are using Microsoft Data Access Components (MDAC) version 2.5, you may need to install the MDAC Software Development Kit (SDK) in order to obtain the Msjetoledb.h file. You can download the SDK from the following Microsoft Web site:

If you are using MDAC 2.1, see the following article for information on how to obtain this header file:

228525 PATCH: JetVC.exe VC++ Support Files for the Jet OLE DB Provider

The following code demonstrates how to create an empty Access database in the location C:\Createdb.mdb:

* Create a blank .mdb file with the Jet 4.0 provider.
#define UNICODE
#define _UNICODE
#define INITGUID

#include <windows.h>
#include <msjetoledb.h> //MDAC SDK
#include <oledb.h>

struct initCom
    initCom() { CoInitialize(NULL); }
    ~initCom() { CoUninitialize(); }
} _inst_initCom;

int main()
    IDBInitialize* pIDBInitialize = NULL;
    IDBDataSourceAdmin*  pIDBDataSourceAdmin = NULL;
    HRESULT  hr;
    const ULONG          nDBProps = 1;
    const ULONG          nPropsets = 1;
    DBPROP         DBProperties[nDBProps];
    DBPROPSET      DBPropSet;
    DBPROPSET      propSetArray[nPropsets];
    DBProperties[0].dwPropertyID = DBPROP_INIT_DATASOURCE; 

    DBProperties[0].vValue.vt = VT_BSTR;
    DBProperties[0].dwOptions = DBPROPOPTIONS_OPTIONAL;
    DBProperties[0].colid = DB_NULLID;
    DBProperties[0].vValue.bstrVal = 
    DBPropSet.guidPropertySet = DBPROPSET_DBINIT;
    DBPropSet.cProperties = nDBProps;
    DBPropSet.rgProperties = DBProperties;
    propSetArray[0] = DBPropSet;
    hr = CoCreateInstance(CLSID_JETOLEDB_4_00,NULL,
        (void**) & pIDBInitialize);
    if (FAILED(hr))
        return (E_FAIL);
    hr = pIDBInitialize->QueryInterface(IID_IDBDataSourceAdmin, 
    if (SUCCEEDED(hr))
        hr = pIDBDataSourceAdmin->CreateDataSource(nPropsets,
    if (pIDBInitialize != NULL)
    return (0);

NOTE: You can modify the version format of the Access .mdb file by setting the DBPROP_JETOLEDB_ENGINE property of the DBPROPSET_JETOLEDB_DBINIT propset. If this property is not specified, the .mdb file is created in the Access 2000/Jet 4.0 format.

Keywords: kbhowto kbjet KB248106