Connecting to SQL instances – the SqlInstance parameter

All commands in dbatools that work with computers or instances have a single parameter to select that target: -ComputerName or -SqlInstance, respectively. Both have the same underlying datatype, allowing you to freely specify anything that legally targets an instance or computer: Server objects, plain computer names, IP addresses, connection strings, ADComputer objects, and so on.

In all instances, if you specify a session object for SQL instances or PowerShell remoting, those sessions will be reused, improving performance.

Unlike the SqlServer module, dbatools does not suffer from the stale data issue, as requests will refresh the data on SQL Session objects. This makes it safe to reuse sessions. Sql Session objects are inter-operable between the SqlServer module and dbatools, though it is not recommended to use them in the same PowerShell process.

There are dozens of ways to tune your connection to a SQL Instance—far too many to pass them through as parameters through every single command. Most commands thus only support the SqlInstance parameter and a credentials parameter. For more control over the actual connection, you can use the dedicated Connect-DbaInstance command, which allows you to tune the actual connection as needed.

Since the SqlInstance parameter passes through such sessions and reuses them, this allows you to easily tune connections as needed, and also removes the need to pass through custom credentials, as those are also dealt with by establishing connections. See the following code:

$server = Connect-DbaInstance -SqlInstance sql2017 -Database db1 -ConnectTimeout 45 -LockTimeout 30 -NetworkProtocol TcpIp -StatementTimeout 15
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.23