I am having some issues connecting to an instance of MSSQL on a Windows server while using mssql_session. Here is the code that I am using for the test:
sql = mssql_session(user: 'user', password: 'Password', host: 'ADDRESS', instance: 'MSSQL')
I am getting the following error:
/opt/inspec/embedded/lib/ruby/gems/2.6.0/gems/inspec-4.18.39/lib/inspec/resources/mssql_session.rb:77:in `query': Could not execute the sql query (Inspec::Exceptions::ResourceFailed)
SQLCMD.EXE : Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: No connection could be made because the target machine actively refused it.
+ CategoryInfo : NotSpecified: (Sqlcmd: Error: ...ely refused it.:String) , RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
I am able to connect to that instance via SQLCMD manually. I took a quick look at the source code, and it appears as though the mssql_session wraps all the parameters in a single quote when calling sqlcmd.
i.e. sqlcmd -S 'server\instance' -U 'user' -P 'Password' If I call sqlcmd manually if this same manner, I get the same error that InSpec is returning.
However if I do the following:
sqlcmd -S "server\instance" -U "user" -P "Password" (using double quotes), I am able to connect to the instance fine.
Has anyone run into this before or have any ideas? Is there something obvious that I have missed?