Skip to content

Instantly share code, notes, and snippets.

@ATLPhenx
Created April 28, 2016 23:34
Show Gist options
  • Save ATLPhenx/429a7b92b1768dc7961327b7002e0bcb to your computer and use it in GitHub Desktop.
Save ATLPhenx/429a7b92b1768dc7961327b7002e0bcb to your computer and use it in GitHub Desktop.
$connectionString = "Server= $SQLServer, $PORT;Database=$SQLDBName;User ID= $Username; Password= $Password;"
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = $connectionString
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = $query
$conn.open()
if ($conn.Open() -eq $true)
{
Write-Host "connection established..."
}
$cmd.connection = $conn
$queryResult = $cmd.ExecuteReader()
$conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment