Connecting to LocalDB
In this recipe, we will connect to the LocalDB database.
Getting ready
LocalDB is a separate installation from your usual instance. LocalDB needs to be installed before you can follow this recipe.
You can download LocalDB with SQL Server Express from MSDN downloads at https://www.microsoft.com/en-ca/download/details.aspx?id=42299.
How to do it...
Let's take a look at the steps to connect to LocalDB:
- Open PowerShell ISE as an administrator.
- Import the
SQLPS
module and create a new SMO Server object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
- Add the following script and run it:
$instanceName = "(localdb)\MSSQLLocalDB" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName #list all databases in localdb $server.Databases
How it works...
LocalDB is a flavor of SQL Server Express that is geared toward developers. You can think of it as a stripped-down version of SQL Server Express—...