Microsoft KB Archive/248106

= 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

-

APPLIES TO


 * 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



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



MORE INFORMATION
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:

http://msdn.microsoft.com/dataaccess

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.
 * 1) define UNICODE
 * 2) define _UNICODE
 * 3) define DBINITCONSTANTS
 * 4) define INITGUID
 * 1) define INITGUID


 * 1) include 
 * 2) include  //MDAC SDK
 * 3) include 

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 = SysAllocString(OLESTR("C:\Createdb.mdb")); DBPropSet.guidPropertySet = DBPROPSET_DBINIT; DBPropSet.cProperties = nDBProps; DBPropSet.rgProperties = DBProperties; propSetArray[0] = DBPropSet; hr = CoCreateInstance(CLSID_JETOLEDB_4_00,NULL,       CLSCTX_INPROC_SERVER,IID_IDBInitialize,         (void**) & pIDBInitialize); if (FAILED(hr)) return (E_FAIL); hr = pIDBInitialize->QueryInterface(IID_IDBDataSourceAdmin,        (void**)&pIDBDataSourceAdmin); if (SUCCEEDED(hr)) hr = pIDBDataSourceAdmin->CreateDataSource(nPropsets,       propSetArray,NULL,IID_IDBDataSourceAdmin,NULL); pIDBDataSourceAdmin->Release; SysFreeString(DBProperties[0].vValue.bstrVal); if (pIDBInitialize != NULL) pIDBInitialize->Release; 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

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.