Building the Application
Follow these steps to write in the BuildApplication method to meet the requirements:
- Create the target database. (This is the end result of the build.)
- Set build properties on the target database.
- Set build properties on the source database.
- Delete data from tables in the target database.
Using programming by intention, write the BuildApplication method as follows. We'll fill in the dependent methods along the way. Start with the declaration and a call to the method.
CreateTargetDatabase. We're wrapping the code in a try/catch block to handle any exceptions that are thrown:
private void BuildApplication() { try { // get the target database targetDatabase = CreateTargetDatabase();
Next, we need to set properties on both the target and source databases. To do that, add the following code. These methods will be implemented in a few moments.
// set properties on the target and source databases SetTargetProperties(); SetSourceProperties();
The next thing we need to do is delete the data from the selected tables. Add the following code to call a method that will do that:
// delete data from tables DeleteTableData();
Next, close the source database and finish the try block:
// close the source database sourceDatabase.Close(); // success! MessageBox.Show("Application built successfully!", "Build Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); }
Two different exceptions may be thrown: a COMException if one of the user-defined properties is null, and NullReferenceException if the target database was not created. Handle both of these exceptions with the following catch blocks. We've added a finally block to make sure that the target database is closed:
catch (COMException ex) { if (ERR_PROP_ISNULL == ex.ErrorCode) { errorText = "Custom database property cannot be null"; ShowErrorMessage(); } } catch (NullReferenceException) { ShowErrorMessage(); } finally { // close target database in the finally block to ensure closure targetDatabase.Close(); } }
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