📄 vcg06.htm
字号:
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
RepairDatabase
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
RepairDatabase()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Repairs a damaged database (if possible). This function takes a single pointer to a string containing the name of the database to be repaired. It's recommended that you subsequently call the CompactDatabase() function after repairing the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CreateWorkspace
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Create()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates a new named CDaoWorkspace object with a specified user ID and password.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
RegisterDatabase
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
None
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates an entry in the registry (32-bit) or in the ODBC.INI file (16-bit) for a named ODBC data source. This functionality isn't directly supported by the CDaoWorkspace object.</FONT>
</TABLE></CENTER><P>The RegisterDatabase() method isn't supported by the DAO MFC classes. If you need to use a DAO functionality that isn't supported by the DAO MFC classes, you can call the functionality directly. For more information, refer to Technical Note 54, "Calling DAO Directly While Using MFC DAO Classes," which can be found on Books Online on the Visual C++ 4 distribution CD.
<BR>
<P>The full syntax of the CompactDatabase method is either this:
<BR>
<PRE>
<FONT COLOR="#000080">static void PASCAL CompactDatabase( LPCTSTR <I>lpszSrcName</I>,
LPCTSTR <I>lpszDestName</I>, LPCTSTR <I>lpszLocale</I> = dbLangGeneral,
int <I>nOptions</I> = 0 );</FONT></PRE>
<P>or, if you want to specify a password, this:
<BR>
<PRE>
<FONT COLOR="#000080">static void PASCAL CompactDatabase( LPCTSTR <I>lpszSrcName</I>,
LPCTSTR <I>lpszDestName</I>, LPCTSTR <I>lpszLocale</I>,
int <I>nOptions</I>, LPCTSTR <I>lpszPassword</I> );</FONT></PRE>
<P>Note that if you want to use a password, you must specify the locale string and options parameters.
<BR>
<P>If you specify the same path and filename for <I>lpszSrcName</I> and <I>lpszDestName</I>, the compacted file replaces the original file. The <I>lpszLocale</I> argument specifies the collating order of the file. The default value is dbLangGeneral (;LANGID=0x0409;CP=1252;COUNTRY=0). The <I>nOptions</I> argument lets you specify the type of the file and whether to encrypt or decrypt the file with the constants listed in Table 6.3.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 6.3. Constants (flags) for the <I>nOptions</I> argument of the <I>CompactDatabase</I> method.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Constant</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Value</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Purpose</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
dbVersion10
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
1
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Compacts to a Microsoft Access 1.0 .MDB file.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
dbVersion11
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
8
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Compacts to a Microsoft Access 1.1 .MDB file.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
dbVersion20
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
16
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Compacts to a Jet 2.5 (Access 2.0) .MDB file.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
dbVersion30
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
32
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Compacts to a Jet 3.0 (Access 7.0) .MDB file.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
dbEncrypt
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
2
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Encrypts the compacted file.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
dbDecrypt
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
4
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Decrypts an encrypted file.</FONT>
</TABLE></CENTER><P>The syntax of the RepairDatabase() method function is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">static void PASCAL RepairDatabase(LPCTSTR <I>lpszName</I>);</FONT></PRE>
<P>where <I>lpszName</I> is the well-formed path to and the filename of the Jet .MDB database file you want to repair.
<BR>
<P>In most cases, Jet databases are secured only in multiuser applications. Thus, use of the DefaultUser(), DefaultPassword(), and IniPath() property functions and the Idle() and CreateWorkspace() method functions is covered in Chapter 19, "Running Visual C++ Database Applications on a Network." The LoginTimeout property and the RegisterDatabase method are two of the subjects of Chapter 3, "Using Visual C++ Data Access Functions," and Chapter 20, "Creating Front Ends for Client-Server Databases."
<BR>
<BR>
<A NAME="E68E39"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Defining the <I>Workspace</I> and <I>Database</I> Objects</B></FONT></CENTER></H3>
<BR>
<P>Most of the preceding sections of this chapter have been devoted to defining terms and classifying data objects by their behavior. This might have confused you, because both MFC DAO terms and "regular" DAO terms are spread throughout this chapter. Generally, if you're not sure whether a term is MFC or DAO, you can search in the Visual C++ Books Online to determine the usage of a particular term. The remainder of this chapter provides a detailed analysis of the properties of and the methods that apply to the CDaoWorkspace and CDaoDatabase objects and to member objects of the CDaoDatabase object. It also tells you how to use these properties and methods in your Visual C++ 4.0 database applications.
<BR>
<P>Before you can get or set the properties of a Database object or apply methods to a Database object, you need to create a variable of the CDaoDatabase type. You can create a class of type CDaoDatabase with the following two lines of Visual C++ code:
<BR>
<PRE>
<FONT COLOR="#000080">CDaoDatabase <I>dbName</I>;
<I>dbName</I>.Open(<I>ConnectArguments</I>);</FONT></PRE>
<BR>
<A NAME="E69E133"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Properties and Methods of the <I>Workspace</I> Object</B></FONT></CENTER></H4>
<BR>
<P>The Workspace is defined as a <I>session</I> of the DBEngine object. A session is an instance of the DBEngine object for a single user, who is identified by a user ID and password, including the default Admin user ID and empty password. Technically, Open() and Create() are methods of the CDaoWorkspace object, because you can't apply a method, such as OpenDatabase, to an object for which a reference doesn't exist. Thus, the following syntax is better at keeping with the principles of object-oriented programming:
<BR>
<PRE>
<FONT COLOR="#000080">CDaoWorkspace wsName;
wsName.Create("database.mdb"); // Create deafult workspace
// Or call Append(...) to append to an existing workspace
CDaoDatabase dbName(wsName);</FONT></PRE>
<P>An additional benefit of creating the default CDaoWorkspace object variable is that you have a pointer for implementing security features and performing transactions for the session with desktop databases, such as Jet, that include security features and support transactions. Jet (Access) security features are one of the subjects of Chapter 19. The use of Jet transactions is covered in Chapter 15, "Designing Online Transaction-Processing Systems." The IsolateODBCTrans, Name, and UserName properties of the Workspace object, which are seldom used in Visual C++ database applications, are described in Chapters 19 and 20. For completeness, Table 6.4 lists the methods of the Workspace object.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 6.4. Methods applicable to the Workspace object.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Method</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>CDaoWorkspace</I><I> Member </I><I>Function</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Purpose/Parameters</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Open
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Open()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Opens an existing workspace object.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Create
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Create()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates a new workspace object.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CreateGroup
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Not implemented
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates a new Group object that you can append to the Groups collection or to a User object.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CreateUser
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Not implemented
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates a new User object that you can append to the Users collection or to a Group object.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
BeginTrans
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
BeginTrans()
</FONT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -