Created
August 10, 2020 16:23
-
-
Save stesee/a31d3ae32eb118005017f37cc1f83af6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-SqlConnection { | |
param( | |
[Parameter(Mandatory)] | |
[string]$ServerName, | |
[Parameter(Mandatory)] | |
[string]$DatabaseName | |
) | |
$connectionString = "Data Source=$ServerName;Integrated Security=true;Initial Catalog=master;Connect Timeout=3;database=$DatabaseName;" | |
$sqlConn = new-object ("Data.SqlClient.SqlConnection") $connectionString | |
$sqlConn.Open() | |
$sqlConn.GetSchema("Tables"); | |
if ($sqlConn.State -eq ‘Open’) { | |
$sqlConn.Close(); | |
"Opened successfully." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment