I'm trying to execute a QC script against a database. This script contains usage of cursors, a lot of sql statements (~400 lines), uses table variables and all kinds of fun stuff.
The script executes fine in SSMS.
I'm trying this to run it via powershell:
$adOpenStatic = 3
$adLockOptimistic = 3
$TargetDatabaseName = 'databaseCatalogName'
$DatabaseName = 'DatabaseName'
$QCChecksLocation = 'C:\thisPathWorks\QC Checks.sql'
Start-Process odbcconf -wait -ArgumentList "/A {CONFIGSYSDSN ""SQL Server Native Client 11.0"" ""DSN=$TargetDatabaseName|Server=$DatabaseName|Database=$TargetDatabaseName|Trusted_Connection=Yes""}"
$TargetConn = New-Object -comObject ADODB.Connection
$QCResults = New-Object -comobject ADODB.Recordset
$TargetConn.ConnectionString = "DSN=$TargetDatabaseName"
$TargetConn.Open()
$SQL = get-content $QCChecksLocation
$QCResults.Open($SQL,$TargetConn,$adOpenStatic,$adLockOptimistic)
This results in the error: Exception calling "Open" with "4" argument(s): "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
Any help?
$sql. Does changing this line help?$SQL = get-content -Raw $QCChecksLocation