Below is simple power shell command for SQL server DB connection
cls
$sqlinstance = "[ServerName]\[InstanceName]"
$auth = “Integrated Security=SSPI;”
$connString = “Provider=SQLNCLI11.1;Auto Translate=False;” + “Data Source=$sqlinstance; ” + “Initial Catalog=myDB; ” + “$auth; “
$connString
$conn = New-Object System.Data.OleDb.OleDbConnection $connString
$conn.Open()
if($conn.State -eq "Open")
{
Write-Host "Test connection successful"
$conn.Close()
}
No comments:
Post a Comment