Set Build Properties on the Target Database
The target database will contain three properties:
- AppVersion - The version number of the application
- AppReleaseDate - The release date of the application
- DEBUG - Indicates whether the database is a debug build
The BuildApplication method calls the method SetTargetProperties to set properties in the target database. Define this method as follows.
private void SetTargetProperties() { SetDatabaseProperty(targetDatabase, DST_PRP_VERSION, DAO.DataTypeEnum.dbText, appVersion.Text); SetDatabaseProperty(targetDatabase, DST_PRP_RELDATE, DAO.DataTypeEnum.dbDate, releaseDate.Value.ToShortDateString()); SetDatabaseProperty(targetDatabase, DST_PRP_DEBUG, DAO.DataTypeEnum.dbBoolean, debugBuild.Checked); // delete properties that may be in the target after doing a copy DeleteDatabaseProperty(targetDatabase, SRC_PRP_APPMAJOR); DeleteDatabaseProperty(targetDatabase, SRC_PRP_APPMINOR); DeleteDatabaseProperty(targetDatabase, SRC_PRP_APPREVISION); DeleteDatabaseProperty(targetDatabase, SRC_PRP_STARTDATE); DeleteDatabaseProperty(targetDatabase, SRC_PRP_TARGET); }
Okay, so you noticed that this doesn't really do much - other than call another method. The SetDatabaseProperty method is used to set the actual property values. This method accepts the Database object so it is used to set properties in both the target and source databases. Add the following code to implement the SetDatabaseProperty method:
private void SetDatabaseProperty(DAO.Database database, string propName, DAO.DataTypeEnum propType, object propValue) { DAO.Container container; DAO.Document document = null; try { // set a database property container = database.Containers["Databases"]; document = container.Documents["UserDefined"]; document.Properties[propName].Value = propValue; }
You'll notice here that we're setting a property in the UserDefined document of the Databases container in the database. Properties created here appear in the Properties dialog box for the database.
If the specified property is not found, we receive the Property Not Found error in DAO. In the .NET Framework, this translates to a COMException. If we receive this error, we need to create the property.
catch (COMException ex) { switch (ex.ErrorCode) { case ERR_PROP_NOTFOUND: // property not found - create it if (!string.IsNullOrEmpty(propValue.ToString())) { DAO.Property prp = targetDatabase.CreateProperty( propName, propType, propValue, Type.Missing); document.Properties.Append(prp); }
If the property value is null, we're going to raise a new COMException to the caller to handle:
else { // raise this exception to the calling routine throw new COMException("", ERR_PROP_ISNULL); } break; default: throw; } }
If the target database did not get created, our code will receive a NullReferenceException so let's handle that as well:
catch (NullReferenceException) { // set the error text errorText = "Target database does not exist. " + "Creating ACCDE/MDE failed." + "\n\nVerify that you can compile the " + "source database and that there are no errors."; } }
If we made a copy of the file, the source database properties may be copied to the target database. The DeleteDatabaseProperty method is used to delete a property from the specified database.
private void DeleteDatabaseProperty(DAO.Database database, string propName) { DAO.Container container; DAO.Document document = null; try { // delete a database property container = database.Containers["Databases"]; document = container.Documents["UserDefined"]; document.Properties.Delete(propName); } catch (COMException){ } }
In this tutorial:
- Deployment
- Creating an Automated Build
- Design the Form
- Retrieving Information from the Source Database
- Building the Application
- Creating the Target Database
- Set Build Properties on the Target Database
- Setting Build Properties on the Source Database
- Deleting Data from Tables
- Calculating the Version Number
- Handling Application Dependencies
- Updating References
- Testing Reference Fix-Up
- Late Binding
- Licensing Your Applications
- Number of Records
- Restricting the Number of Times an Application is Launched
- Registering an Application
- Creating a Registration Web Service
- Validate the Registration Using the Web Service
- Miscellaneous Deployment Scenarios
- Create the Client Application
- Testing the Versioning Server
- Re-Linking Tables Automatically
- Programmatically Creating DSNs
- Creating a User DSN
- Ensuring an Application Runs Locally