CreateWorkspace Method

       

Creates a new CdbWorkspace object.

Syntax

CdbWorkspaceCreateWorkspace(LPCTSTR pstrName,

LPCTSTR pstrUser,

LPCTSTR pstrPassword,

LONG lType = dbUseJet);

Parameters

Type Argument Description
LPCTSTR pstrName A pointer to a string that uniquely names the new CdbWorkspace object. See the Name property for details on valid workspace names.
LPCTSTR pstrUser A pointer to a string that identifies the owner of the new CdbWorkspace object. See the UserName property for more information.
LPCTSTR pstrPassword A pointer to a string containing the password for the new CdbWorkspace object. The password can be up to 14 characters long and can include any characters except ASCII character 0 ( null ). See the Password property for more information on valid passwords.
LONG Itype An integer that specifies whether the type of the workspace should be Microsoft Jet or ODBC. The default is a Microsoft Jet workspace.

Settings

You can use the following constants for lType.

Constant Description
dbUseJet Creates a Microsoft Jet workspace.
dbUseODBC Creates an ODBCDirect workspace.

Remarks

Once you use the CreateWorkspace method to create a new CdbWorkspace object, a CdbWorkspace session is started, and you can refer to the CdbWorkspace object in your application.

CdbWorkspace objects aren't permanent and you can't save them to disk. Once you create a CdbWorkspace object, you can't alter any of its property settings, except for the Name property, which you can modify before appending the CdbWorkspace object to the Workspaces collection.

You don't have to append the new CdbWorkspace object to a collection before you can use it. You append a newly created CdbWorkspace object only if you need to refer to it through the Workspaces collection.

The lType option determines whether the new CdbWorkspace is a Microsoft Jet or ODBCDirect workspace. If you set lType to CdbUseODBC and you haven't already created any Microsoft Jet workspaces, then the Microsoft Jet database engine will not be loaded into memory, and all activity will occur with the ODBC data source subsequently identified in a CdbConnection object. If you omit lType, the DefaultType property of CdbDBEngine will determine which type of data source the CdbWorkspace is connected to. You can have both Microsoft Jet and ODBCDirect workspaces open at the same time.

To remove a CdbWorkspace object from the Workspaces collection, close all open databases and connections and then use the Close method on the CdbWorkspace object.

Usage

#include <afxole.h>
#include <dbdao.h>
CdbDBEngine      dben;
CdbWorkspace      ws;
ws = dben.CreateWorkspace(   _T("MyWorkSpace"), _T("IOwnIt"),                               _T("MyPassword"), dbUseJet);