Opens a specified database
|cName||A string that is the name of an existing Microsoft Jet database file or the data source name (DSN) of an ODBC data source.|
|uOptions||(Optional) A usual value that specifies how the database should be opened (see below)|
|lReadOnly||(Optional) TRUE Opens a Database for read-only access.|
FALSE (Default) Opens a Database object for read/write access
|cConnect||(Optional) A string composed of a database type specifier and zero or more parameters separated by semicolons. This parameter passes additional information to ODBC and certain ISAM drivers as needed|
A Database Object
For Microsoft Jet workspaces, you can use the following values for the uOptions argument.
True Opens the database in exclusive mode.
False (Default) Opens the database in shared mode.
For ODBCDirect workspaces, the uOptions argument determines if and when to prompt the user to establish the connection. You can use one of the following constants.
|dbDriverNoPrompt||The ODBC Driver Manager uses the connection string provided in pstrName and pstrConnect. If you don't provide sufficient information, a run-time error occurs.|
|dbDriverPrompt||The ODBC Driver Manager displays the ODBC Data Sources dialog box, which displays any relevant information supplied in pstrNname or pstrConnect. The connection string is made up of the DSN that the user selects via the dialog boxes, or, if the user doesn't specify a DSN, the default DSN is used.|
|dbDriverComplete||Default. If the pstrConnect argument includes all the necessary information to complete a connection, the ODBC Driver Manager uses the string in pstrConnect. Otherwise it behaves as it does when you specify dbDriverPrompt.|
|dbDriverCompleteRequired||This option behaves like dbDriverComplete except the ODBC driver disables the prompts for any information not required to complete the connection.|
Password protected databases
To open a database that is protected with a password you must use the following syntax:
oDatabase := oWs:OpenDataBase("C:\Foo\Bar.mdb" ,FALSE,FALSE,;
";pwd=Secret" ) // Shared & Read/write
Please note that the second and third argument are NOT OPTIONAL when opening a database that is password protected
When you open a database, it is automatically added to the Databases collection. Further, in an ODBCDirect workspace, the Connection object corresponding to the new Database object is also created and appended to the Connections collection of the same Workspace object.
Some considerations apply when you use cName:
|•||If it refers to a database that is already open for exclusive access by another user, an error occurs.|
|•||If it doesn't refer to an existing database or valid ODBC data source name, an error occurs.|
|•||If it's a zero-length string ("") and cConnect is "ODBC;", a dialog box listing all registered ODBC data source names is displayed so the user can select a database.|
|•||If you're opening a database through an ODBCDirect workspace and you provide the DSN in cConnect, you can set cName to a string of your choice that you can use to reference this database in subsequent code.|
The cConnect argument is expressed in two parts: the database type, followed by a semicolon (;) and the optional arguments. You must first provide the database type, such as "ODBC;" or "FoxPro 2.5;". The optional arguments follow in no particular order, separated by semicolons. One of the parameters may be the password (if one is assigned). For example:
"FoxPro 2.5; pwd=mypassword"
To close a database, and thus remove the Database object from the Databases collection, use the Close method on the object.
|Note||When you access a Microsoft Jet-connected ODBC data source, you can improve your application's performance by opening a Database object connected to the ODBC data source, rather than by linking individual TableDef objects to specific tables in the ODBC data source.|