Skip to content

Analysis Context

The Analysis Context represents the current server and database schema information that SQL Enlight loads before starting the analysis.

The analysis context is an XML document that holds information for the current SQL Server, the current database.

The current database is determined initially from the SQL connection and later by the database switches ( USE [DatabaseName] statements) inside the script.

Analysis Context XML Schema is included in SQL Enlight installation: \Schemas\AnalysisContext.xsd

Example XPath expression for retrieving the XML node of the function ufnGetAccountingStartDate from database AdventureWorks:

<xsl:variable name="function" select="$context/Server/Databases/Database[@Name='AdventureWorks']/Functions/Function[@Name='ufnGetAccountingStartDate']"/>

Or

<xsl:variable name="function" select="$server/Databases/Database[@Name='AdventureWorks']/Functions/Function[@Name='ufnGetAccountingStartDate']"/>

The same XPath expression, but assuming that the ‘AdventureWorks’ database is the current database:

<xsl:variable name="function" select="$database/Functions/Function[@Name='ufnGetAccountingStartDate']"/>

Sometimes it can be handy to be able to test your analysis rules using different than the default test analysis context.

You can create your own analysis context XML for testing your analysis rules either by editing the AdventureWorksone or by using the Enlightcommand line tool with command analysiscontext.

Analysis Rule