Database - Stored Procedure

Declaration

<AMSQLSTOREDPROC PROCEDURE="text" NAMES="text" VARIABLES="text" TYPES="text" DIRECTIONS="text" VALUES="text" PRECISIONS="number" NUMSCALES="number" SIZES="number" ATTRIBUTES="text" />

Description:

Executes a stored procedure via OLEDB on the datasource specified. Stored procedures are configured on the database server and are often faster than repeated SQL calls. A working knowledge of SQL is necessary to get the most out of this activity.

NOTE: Because the results retrieved from a query may contain multiple records (rows) and multiple fields (columns), to access the data, you must use the Loop Dataset activity to iterate the records and embedded expressions in order to extract the data from the individual fields. See Datasets below for more information.

Practical Usage

Useful for automated retrieval, update and management of data. Could also be used to test database response times and size quotas. Some key benefits include:

Parameters

General

Property

Type

Required

Default

Markup

Description

Connection

 

 

 

 

Indicates where the connection string should originate from. This is a design time parameter used only during task construction and configuration, thus, comprises no markup. The available options are:

  • Host (default) - A new or existing connection string will be set individually for this activity.  Select this option if performing a single database operation.

  • Session - The connection string should derive from a session created by a previous Open SQL Connection step. This allows several queries to be linked to a specific session.

  • System - The connection string will derive from one configured and saved for the system.

Type

Text (options)

Yes if Connection set to Host

 

  1. CONNECTIONTYPE="database"

  2. CONNECTIONTYPE="connection_string"

  3. CONNECTIONTYPE="file"

The type of connection string to use. This parameter is active only of the Connection parameter is set to Host. The available options are:

  • Database (default) - Database connection will derive from a new OLEDB connection string created via the Data Link Properties Wizard. Press the Build Connection button to open the Data Link Properties Wizard. Press the Clear button to clear an existing connection string.

  • Connection string - Database connection will be established using a specific connection string. Enables you to copy an existing string onto the properties of this activity.

  • Data link file - Connection will be established via the data link file specified.

Database connection

Text

Yes if Type set to Database

(Empty)

CONNECTIONSTRING=

"AM1P2qCkbYiFHdqWN7qDphOEw==aME"

Specifies a custom OLEDB connection string. The connection string provides driver, server, username, password and other important information to the OLEDB subsystem so that the connection can be made. To generate a connection string, press the Build connection button. This opens the Data Link Properties Wizard dialog which will help you with construct of your connection string. To clear an existing connection string, press the Clear button. This parameter is available only if the Type parameter is set to Database.

Connection string

Text

Yes if Type set to Connection string

(Empty)

PREDEFINEDCONNECTION=

"%MyPreDefinedConnection%"

Specifies the OLEDB connection string. Use this option to copy an existing connection string and paste it in the provided text box. This parameter is available only if the Type parameter is set to Connection string.

Data link file

Text

Yes if Type set to Data link file

(Empty)

CONNECTION="c:\temp\fileName.udl"

The path and filename of the data link (.udl,.dsn) file to connect with. Click the folder icon to open a standard Explorer dialog allowing for easy navigation to the desired data link file. This parameter is active only if the Type parameter is set to Data link file.

Prompt user for a name and password

Yes/No

No

No

LOGIN="YES"

If set to YES, specifies that the user should be prompted to enter a username and password for the database server each time the task is run.Set to NO by default.

Protect connection string

 

 

 

 

If enabled, the value entered in the Connection string parameter will be encrypted in both visual and AML mode as a means of protecting data embedded in the connection string. If disabled (default), the connection string will appear as normal readable text. Enable this option if your connection string contains sensitive data that you may not want others to view. This is a visual mode parameter used only during design time, therefore, contains no properties or markup. It is available only if the Type parameter is set to Connection string.

Stored Procedure

Text

Yes

(Empty)

PROCEDURE="EXECUTE sp_GetInventory 'FL'"

Specifies the stored procedure to execute.

Parameters

Text

No

(Empty)

NAMES="Name"

VARIABLES="var_1"

TYPES="String" DIRECTIONS="Input" VALUES="Value"

PRECISIONS="2"

NUMSCALES="22"

SIZES="2"

ATTRIBUTES="Signed"

Specifies the parameters of the stored procedure to execute. Click the Add button to add parameters.

Stored Procedure

Property

Type

Required

Default

Markup

Description

Stored Procedure

Text

Yes

(Empty)

PROCEDURE="EXECUTE sp_GetInventory 'FL'"

Specifies the stored procedure to execute.

Parameters

Text

No

(Empty)

NAMES="Name"

VARIABLES="var_1"

TYPES="String" DIRECTIONS="Input" VALUES="Value"

PRECISIONS="2"

NUMSCALES="22"

SIZES="2"

ATTRIBUTES="Signed"

Specifies the parameters of the stored procedure to execute. Click the Add button to add parameters. This opens a Stored Procedure Parameters dialog in which to enter the desired parameters. Upon completion, a new line of parameters will appear in Parameters grid. To edit an existing line of parameters, highlight it and click the Edit button. To delete an existing line of parameters, highlight it and click the Delete button.

Advanced

Property

Type

Required

Default

Markup

Description

The stored procedure times out after (optional)

Number

No

(Empty)

TIMEOUT="2"

The amount of time that the query should be allowed before timing out at the server level.

Measure

Text (options)

No

Seconds

MEASURE="minutes"

 The time measurement that should correspond to the stored procedure timeout value entered. The available options are:

  • Milliseconds - The timeout value is measured in milliseconds.

  • Seconds (default) - The timeout value is measured in seconds.

  • Minutes - The timeout value is measured in minutes.

  • Hours - The timeout value is measured in hours.

Create and populate dataset (optional)

Text

No

(Empty)

RESULTDATASET="theData"

The name of the dataset that should be created and populated with the results (if any) of the stored procedure upon execution. To access the data in subsequent steps simply specify %datasetname.fieldname% (where 'datasetname' specifies the name of the dataset and 'fieldname' specifies the name of the dataset field) inside a Loop Dataset activity (to recurse the rows). More details regarding datasets can be found below under Datasets.

Description

Error Causes

On Error

Datasets

A dataset is a multiple column, multiple row container object. This activity creates and populates a dataset. The fields contained within that dataset are determined by the query that was executed. For example if the following query is executed:

SELECT firstname, lastname, company from customer where city='Los Angeles';

Then the following dataset would be generated (where datasetname specifies the name of the dataset):

datasetname.firstname

datasetname.lastname

datasetname.company

A record (row) is created for each record (row) that is retrieved from the server. To access this data use the Loop Dataset Action to loop through the records, inside the loop you can extract the data from the field of your choice (from the current record) by using an embedded expression such as the one that follows:

%datasetname.firstname%

or you could combine two fields together like this:

%datasetname.firstname + " " + datasetname.lastname%

Embedded Expressions such as these can be used in any parameter in any action. So, to display the data in a message box the AML code would look like this:

 <AMMESSAGEBOX MESSAGETEXT="%datasetname.firstname%" WINDOWTITLE="The firstname of the current record is">

At runtime the text %datasetname.firstname% is replaced by the contents of the subject of the current record.

Along with the above fields, there are standard fields included in every dataset. The table below describes these fields (assuming the name of the dataset is theDataset):

Name

Data Type

Return Value

theDataset.CurrentRow

Number

The current row that will be accessed in the dataset by an expression that does not contain a specific row index.

theDataset.TotalRows

Number

The total number of rows in the dataset

theDataset.TotalColumns

Number

The total number of columns (not including the static columns) in the dataset.

theDataset.ExecutionDate

Date

The date and time the dataset was created and populated

theDataset.RowsAffected

Number

The number of rows affected by an update.

theDataset.SQLQuery

Text

The SQL Query that was used to generate this dataset (If a SQL Query was not used, this value is empty).

theDataset.Datasource

Text

The datasource used for the SQL Query, if applicable.

theDataset.ColumnNames

Text

A comma-delimited list of the column names in the dataset

Example

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

Description: Execute the stored procedure: "EXECUTE sp_GetInventory 'FL'".  The parameters are: "Name" (names), "var_1" (variables to hold the values), "String" (types), "Input" (directions), "Value" (values), "2" (max. number of characters that can appear to the right of the decimal place), "22" (max. number of digits allowed in the parameter), "2" (sizes), "Signed" (type of values accepted by the parameter).  

<AMSQLSTOREDPROC PROCEDURE="EXECUTE sp_GetInventory 'FL'" NAMES="Name" VARIABLES="var_1" TYPES="String" DIRECTIONS="Input" VALUES="Value" PRECISIONS="2" NUMSCALES="22" SIZES="2" ATTRIBUTES="Signed" />