Part 1 of 3
First, If you already have install Visual Studio, and/or SQL Server then you probably the ADO.NET already loaded.
So, here's an example on how to connect to SQL Server using Windows trusted authentication. Following best practices, so no hard-coding UserID and Password needed.
Connecting to SQL Server
|
## - Defining your SQL Server Parameters
$SqlServer = "YourSQLServerName";
$SqlDatabase = "YourDatabaseName";
## - Building the SQL connection string
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection;
$SqlConnection.ConnectionString = "Server = $SqlServer; Database = $SqlDatabase; " `
+ "Integrated Security = True; Connect TimeOut=300";
## Open SQL Coonection
$SqlConnection.Open();
## - Other statements comes here
## - Close connection to SQL Server
$SqlConnection.Close();
## - End of Script
|
This code will get you connected and you only need to additional code to work with your SQL Server.
Please check out part 2 of 3 on this series Next...