Sha256: 5714abde1e1e0eeadbbb915d3d46691eaf4347ca79af391d682d79ca74f58926

Contents?: true

Size: 1.94 KB

Versions: 17

Compression:

Stored size: 1.94 KB

Contents

---
title: About the mssql_session Resource
---

# mssql_session

Use the `mssql_session` InSpec audit resource to test SQL commands run against a Microsoft SQL database.

<br>

## Syntax

A `mssql_session` resource block declares the username and password to use for the session, and then the command to be run:

    describe mssql_session(user: 'username', password: 'password').query('QUERY').row(0).column('result') do
      its('value') { should eq('') }
    end

where

* `mssql_session` declares a username and password with permission to run the query.  Omitting the username or password parameters results in the use of Windows authentication as the user InSpec is executing as.  You may also optionally pass a host and instance name.  If omitted, they will default to host: localhost and the default instance.
* `query('QUERY')` contains the query to be run
* `its('value') { should eq('') }` compares the results of the query against the expected result in the test

<br>

## Examples

The following examples show how to use this InSpec audit resource.

### Test for matching databases

    sql = mssql_session(user: 'my_user', password: 'password')

    describe sql.query("SELECT SERVERPROPERTY('ProductVersion') as result").row(0).column('result') do
      its("value") { should cmp > '12.00.4457' }
    end

### Test using Windows authentication

    sql = mssql_session

    describe sql.query("SELECT SERVERPROPERTY('ProductVersion') as result").row(0).column('result') do
      its("value") { should cmp > '12.00.4457' }
    end

### Test a specific host and instance

    sql = mssql_session(user: 'my_user', password: 'password', host: 'mssqlserver', instance: 'foo')

    describe sql.query("SELECT SERVERPROPERTY('ProductVersion') as result").row(0).column('result') do
      its("value") { should cmp > '12.00.4457' }
    end

<br>

## Matchers

For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
inspec-1.51.25 docs/resources/mssql_session.md.erb
inspec-1.51.21 docs/resources/mssql_session.md.erb
inspec-1.51.18 docs/resources/mssql_session.md.erb
inspec-1.51.6 docs/resources/mssql_session.md.erb
inspec-1.51.0 docs/resources/mssql_session.md.erb
inspec-1.50.1 docs/resources/mssql_session.md.erb
inspec-1.49.2 docs/resources/mssql_session.md.erb
inspec-1.48.0 docs/resources/mssql_session.md.erb
inspec-1.47.0 docs/resources/mssql_session.md.erb
inspec-1.46.2 docs/resources/mssql_session.md.erb
inspec-1.45.13 docs/resources/mssql_session.md.erb
inspec-1.45.9 docs/resources/mssql_session.md.erb
inspec-1.44.8 docs/resources/mssql_session.md.erb
inspec-1.43.8 docs/resources/mssql_session.md.erb
inspec-1.43.5 docs/resources/mssql_session.md.erb
inspec-1.42.3 docs/resources/mssql_session.md.erb
inspec-1.41.0 docs/resources/mssql_session.md.erb