Skip to content

Commit 9a25126

Browse files
Test-DbaLinkedServerConnection - Fix test failure when Named Pipes is disabled
Force TCP/IP by specifying @datasrc=N'tcp:$target' when creating the linked server in test setup. Without this, MSOLEDBSQL defaults to Named Pipes which fails in environments where Named Pipes is not enabled. (do Test-DbaLinkedServerConnection) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent 8987045 commit 9a25126

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/Test-DbaLinkedServerConnection.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ Describe $CommandName -Tag IntegrationTests {
3030
$server = Connect-DbaInstance -SqlInstance $TestConfig.InstanceSingle
3131
if ($server.VersionMajor -ge 17) {
3232
# Starting with SQL Server 2025 (17.x), MSOLEDBSQL uses Microsoft OLE DB Driver version 19, which adds support for TDS 8.0. However, this driver introduces a breaking change. You must now specify the encrypt parameter.
33-
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'', @provider=N'MSOLEDBSQL', @provstr = N'encrypt=optional;TrustServerCertificate=yes'")
33+
# Use @datasrc with tcp: prefix to force TCP/IP and avoid Named Pipes dependency.
34+
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'', @provider=N'MSOLEDBSQL', @datasrc=N'tcp:$target', @provstr = N'encrypt=optional;TrustServerCertificate=yes'")
3435
} elseif (-not $env:AppVeyor) {
35-
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'', @provider=N'MSOLEDBSQL'")
36+
# Use @datasrc with tcp: prefix to force TCP/IP and avoid Named Pipes dependency.
37+
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'', @provider=N'MSOLEDBSQL', @datasrc=N'tcp:$target'")
3638
} else {
3739
# AppVeyor images do not have the MSOLEDBSQL provider installed, so we use SQLNCLI11 instead
3840
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'SQL Server'")

0 commit comments

Comments
 (0)