Setting up database connections
Published 21 May 2018
If you use a database as a source for any of the SQL Change Automation cmdlets, you'll first need to use the New-DatabaseConnection
cmdlet to set up the connection details to the database. You can also use the Test-DatabaseConnection
cmdlet to check the connection works. This page provides an overview of these cmdlets.
New-DatabaseConnection
Use this cmdlet to specify the connection details for a database, which you can then use as the input for other SQL Change Automation cmdlets.
Example
New-DatabaseConnection -ServerInstance "test01\sql2014" -Database "AdventureWorksIntegration"
If you aren't using Windows Authentication, you'll also need to specify the username and password for the SQL Server account:
Example
New-DatabaseConnection -ServerInstance "test01\sql2014" -Database "AdventureWorksIntegration" -Username "sa" -Password "P@ssw0rd"
By assigning the output of New-DatabaseConnection
to a variable, you can reuse this as the input for another cmdlet:
Example
$testdb = New-DatabaseConnection -ServerInstance "test01\sql2014" -Database "AdventureWorksIntegration" Sync-DatabaseSchema -Source "C:\Work\scripts" -Target $testdb
In the example above, we've assigned the connection to our test database to the variable, $testdb
. We've then used this as the input for the Sync-DatabaseSchema
cmdlet.
Test-DatabaseConnection
Use this cmdlet to check the connection you specified in the New-DatabaseConnection
cmdlet works.
Example
$testdb = New-DatabaseConnection -ServerInstance "test01\sql2014" -Database "Test" | Test-DatabaseConnection
In the example above, we've used the pipe (|) symbol to take the output of New-DatabaseConnection
and input it into Test-DatabaseConnection
.
If New-DatabaseConnection
can't connect to the database, it raises an error.
What next?
You're now ready to learn how to use New-DatabaseConnection
and Test-DatabaseConnection
with other SQL Change Automation cmdlets, to set up Continuous Integration.
Cmdlet reference
For full details about all the SQL Change Automation cmdlets, see the SQL Change Automation cmdlet reference.