I'm getting the following exception:
New-Object : Cannot find an overload for "SqlCommand" and the argument count: "2". At C:\Users\aaaaaaaaaaaaaaaaaaps.ARMTemplate\CoreDbScripts\RunSqlScripts.ps1:128 char:19
- ... $comm = New-Object System.Data.SqlClient.SqlCommand( $file,$conn) ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
- FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Here's my code:
Using-Object ($conn = New-Object System.Data.SqlClient.SqlConnection $connString) {
$conn.Open();
Using-Object ($tran = $conn.BeginTransaction) {
foreach ($file in $sqlFiles)
{
Write-Host "file: " $file.Name
$comm = New-Object System.Data.SqlClient.SqlCommand($file, $conn);
$comm.Transaction = $tran
[void]$comm.ExecuteNonQuery()
}
$tran.Commit();
};
};
What am I doing wrong? How do we execute the SqlCommand
?