Zero Touch Installation Deployment Feature Team Guide

Appendix J: Sample Stored Procedure Calls

Published: August 27, 2005

Listing 45 lists the BDDAdminDB-IdentifyComputer.sql script that is called by the [DB_IdentifyComputer] section in the excerpt from the sample Customsettings.ini file in Listing 46.  

In this example, BDDAdminDB-IdentifyComputer.sql :

Creates a table, called MachineNameSequence, which contains the columns listed in Table 58.

Table 58. Columns in the MachineNameSequence Table and a Description of the Columns

ColumnDescription

Prefix

Prefix to include as the leading portion of the generated computer name (for example WRKSTA- in the generated name WRKSTA-00021).

Sequence

Last number used to generate the sequence portion of the generated computer name (for example 00021 in the generated name WRKSTA-00021

Creates a stored procedure, called IdentifyComputer, which creates a unique computer name, and then updates the AdminDB database with the new computer name, the MAC address, the make of the workstation, and the model of the workstation.

Note   In the new machine scenario, you may want to include additional logic in the IdentifyComputer stored procedure to automatically populate the OSDINSTALLPACKAGE and OSDINSTALLPROGRAM columns (for example, based on the make and model passed). The current version of the script does not have this feature implemented.

Note Some parts of the following code snippet have been displayed in multiple lines only for better readability. These should be entered in a single line.

use [BDDAdminDB]
GO
 
if exists (select * from dbo.sysobjects where 
id = object_id(N'[dbo].[IdentifyComputer]')  

and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[IdentifyComputer]
GO
 
if exists (select * from dbo.sysobjects where 
id = object_id(N'[dbo].[MachineNameSequence]')  

and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MachineNameSequence]
GO
 
 
CREATE TABLE [dbo].[MachineNameSequence] (
    [Prefix] [varchar] (50) 
COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Sequence] [int] NOT NULL 
) ON [PRIMARY]
GO
 
INSERT INTO [dbo].[MachineNameSequence] 
(Prefix, Sequence) VALUES ('PC', 0)
GO
 
 
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
 
 
CREATE PROCEDURE [dbo].[IdentifyComputer]
@MacAddress CHAR(17),
@Make VARCHAR(50),
@Model VARCHAR(50)
AS
 
DECLARE @Cnt INT,
        @Prefix VARCHAR(50),
        @Sequence INT,
        @NewName VARCHAR(50)
 
SET NOCOUNT ON
 
/* See if there is an existing record for this machine */
 
SELECT @Cnt=COUNT(*) FROM BDDAdminCore
WHERE MacAddress = @MacAddress
 
/* No record?  Add one.  */
 
IF @Cnt = 0
BEGIN
 
    /* Create a new machine name */
 
    BEGIN TRAN
 
    SELECT @Prefix=Prefix, @Sequence=Sequence
FROM MachineNameSequence
    SET @Sequence = @Sequence + 1
    UPDATE MachineNameSequence SET 
Sequence = @Sequence
    SET @NewName = @Prefix + 
Right('00000'+LTrim(Str(@Sequence)),5)
 
    /* Insert the new record */
 
    INSERT INTO BDDAdminCore (MacAddress,
Make, Model, ComputerName, OSDNewMachineName,  
OSDInstallSilent, OSInstall) 
    VALUES (@MacAddress, @Make, @Model, 
@NewName, @NewName, '1', 'Y')
 
    COMMIT TRAN
 
END
 
/*  Return the record as the result set */
 
SELECT * FROM BDDAdminCore
WHERE MacAddress = @MacAddress
 
 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Listing 45. BDDAdminDB-IdentifyComputer.sql script to create table and IdentifyComputer stored procedure

    .
    .
    .
[IdentifyComputer]
SQLDefault=DB_IdentifyComputer
 
[DB_IdentifyComputer]
SQLServer=SERVER1
Database=BDDAdminDB
StoredProcedure=IdentifyComputer
Parameters=MacAddress, Make, Model

Listing 46. Excerpt from the Customsettings.ini file that calls the IdentifyComputer stored procedure


Top of pageTop of pagePrevious21 of 25Next
**
In This Article
**