# MSSQL test for Inspec 3.x

**URL:** <https://discourse.chef.io/t/mssql-test-for-inspec-3-x/14691>\
**Category:** Chef InSpec\
**Created:** [March 8, 2019, 12:20pm UTC](https://discourse.chef.io/t/mssql-test-for-inspec-3-x/14691 "2019-03-08T12:20:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigontour](https://avatars.discourse-cdn.com/v4/letter/c/7ab992/32.png) [@craigontour](https://discourse.chef.io/u/craigontour)\
**Post date:** [March 8, 2019, 12:20pm UTC](https://discourse.chef.io/t/mssql-test-for-inspec-3-x/14691/1 "2019-03-08T12:20:53Z")

</div>

Previously this was thought to be an issue with 'stdout'. Updated....

Since updating our Jenkins/build servers to Inspec 3.0.52 we are seeing a problem with mssql control.

> control "cookbook\_name-database\_exist?" do  
> impact 1.0  
> title 'Check if the specified databases exist.'
> 
> database\_list.each do |db, \_params|  
> next if db.nil?
> 
> ```
> describe mssql_session.query("(SELECT name FROM master.sys.databases WHERE name = N'#{db}');") do
> its('stdout') { should match(/#{db}/) }
> end
> 
> ```
> 
> end  
> end

Error is:

> [FAIL] cookbook\_name-database\_exist?: Check if the specified databases exist.  
> [FAIL] SQL ResultSet stdout  
> undefined method `stdout' for SQL ResultSet:DatabaseHelper::SQLQueryResult

I read Inspec 3.0 resource docs for mssql and changed to:

> ```
> describe mssql_session.query("(SELECT name FROM master.sys.databases WHERE name = N'#{db}') as result").row(0).column('result') do
> its('value') { should match(/#{db}/) }
> end
> 
> ```

But this did not work either.

Can anyone please direct me at docs to understand the msql resource and how its results are structured?

Thanks in advanced for your help.

---

<div class="post-metadata">

**Author:** ![craigontour](https://avatars.discourse-cdn.com/v4/letter/c/7ab992/32.png) [@craigontour](https://discourse.chef.io/u/craigontour)\
**Post date:** [March 11, 2019, 1:36pm UTC](https://discourse.chef.io/t/mssql-test-for-inspec-3-x/14691/2 "2019-03-11T13:36:38Z")

</div>

So I worked out that this it returns a "table" of results from the query that can be referenced by row and column.

> describe mssql\_session.query('SELECT name from master.sys.databases where name='mydb').row(0).column'name')  
> its('value') { should match /mydb/ }  
> end

Neat.
