Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close opened SQL Session without closing PowerShell #23

Open
scriptkiddy666 opened this issue Mar 16, 2017 · 0 comments
Open

Close opened SQL Session without closing PowerShell #23

scriptkiddy666 opened this issue Mar 16, 2017 · 0 comments

Comments

@scriptkiddy666
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant