Skip to content

Instantly share code, notes, and snippets.

@stesee
Created August 10, 2020 16:23
Show Gist options
  • Save stesee/a31d3ae32eb118005017f37cc1f83af6 to your computer and use it in GitHub Desktop.
Save stesee/a31d3ae32eb118005017f37cc1f83af6 to your computer and use it in GitHub Desktop.
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