-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Hey Mike,
I'm a little bit confused. What is the right way to open one single connection to an SQL Server via your module, so that every Get-Sql or Set-Sql command is using this session and how to close this session after several operations.
I managed this like the following:
$sqlsrv = Get-SqlServer -sqlserver $ServerName
$sqldb = Get-SqlPSXDatabase -sqlserver $sqlsrv -dbname $DBName
My Get- and Set-SqlData now looks like this:
Get-SqlData -sqlserver $sqlsrv -dbname $sqldb -qry $SQLQuery
If I run my script this way, all seems to be quiet fine, but I'm unable to manually close this server and/or database connection. The server session is automatically closed, then I close my PowerShell session.
If I would establish several connections to different servers and/or different databases it would be fine to close some not need session within the script and not then the scripts terminates or?
Regards
Markus