-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Labels
Description
Hi when using Invoke-SQL to restore a snapshot I encountered a time-out.
This left the database in restoring state.
Would be nice to have a timeout parameter added to Invoke-SQL, i.e. like this:
Invoke-SQL_SLOW -DatabaseServer $DatabaseServer -DatabaseName 'master' -SQLCommand $RestoreSnapshotSQL -Verbose -ErrorAction Stop -TimeOut 10000
Altered version of Invoke SQL:
function Invoke-SQL_SLOW {
[CmdLetBinding()]
param(
[string] $DatabaseServer = [net.dns]::gethostname(),
[String] $DatabaseInstance = '',
[string] $DatabaseName = 'Master',
[string] $SQLCommand = $(throw 'Please specify a query.'),
[string] $TimeOut = 30
)
if (!([string]::IsNullOrEmpty($DatabaseInstance))){
$DatabaseServer = "$($DatabaseServer)\$($DatabaseInstance)"
}
$connectionString = "Data Source=$DatabaseServer; Integrated Security=SSPI; Initial Catalog=$DatabaseName"
write-Host -ForegroundColor Green "Invoke-SQL-SLOW with this statement on database '$DatabaseName':"
Write-Host -ForegroundColor Gray $SQLCommand
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
$command.CommandTimeout =$TimeOut
$connection.Open()
$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
$dataset = New-Object System.Data.DataSet
$adapter.Fill($dataSet) | Out-Null
$connection.Close()
$connection.Dispose()
$dataSet.Tables
}
Reactions are currently unavailable