BDD Scenarios: Automating Application Deployment

Scenario 1: Using Role Values to Query a Database

Published: March 8, 2005

In more complex environments, maintaining all configuration information in the CustomSettings.ini file may be too difficult. As an alternative, database access information can be specified. As described above, the Role custom key must be added to the CustomSettings.ini file CustomKeysUserData line to instruct the rules engine to attempt to find the value. Then, instead of using the retrieved value directly to find a matching section, the value can be used as part of a database query. To configure this, there must first be a database table to query. The following table can be created in the BDDAdminDB database.

use [BDDAdminDB]
go

if exists 
 (select * from dbo.sysobjects where id = object_id(N'[dbo].[RolePackages]') 
 and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[RolePackages]
go

CREATE TABLE [dbo].[RolePackages] (
	[Role] [nvarchar] (50),
	[Packages] [nvarchar] (50)
)
go

Now, you can populate that table with rows for each role. Continuing with the "Accounting" example above, you could insert three rows for each of the packages that need to be installed.

use [BDDAdminDB]
go

insert into RolePackages 
  (Role, Packages) values('Accounting', 'XXX00001-Program name 1')
go 
insert into RolePackages 
  (Role, Packages) values('Accounting', 'XXX00002-Program name 2')
go
insert into RolePackages 
  (Role, Packages) values('Accounting', 'XXX00003-Program name 3')
go

Now, the CustomSettings.ini file must be configured to query this database table by specifying the name of a section (in the Priority list) that points to the database information.

[Settings]
…
Priority=MacAddress, DefaultGateway, RoleQuery, Default
CustomKeysUserData=UDShare, UDDir, UDProfiles, SLShare, OSInstall, 
Packages(*), Administrators(*), PowerUsers(*), DriverPath(*), Role
…

This new RoleQuery section must then specify the name of a database section.

[RoleQuery]
SQLDefault= DB_RoleQuery

Then that section specifies the database connection information and query details.

[DB_RoleQuery]
SQLServer=SERVER1
Database=BDDAdminDB
Table=RolePackages
Parameters=Role
SQLShare=Logs

In this case, the BDDAdminDB database on the computer running Microsoft SQL Server™ named SERVER1 will be queried. This database contains a table named RolePackages (created above) and the value of the Role custom key will be used to automatically create a query.

SELECT * FROM RolePackages WHERE Role = ?

The actual value of the Role custom key will be substituted for the "?" above. This query would return a recordset with three rows; each of which specifies one package to be added to the list of packages to be installed during the state restore phase.


**
In This Article
**