You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: public/Copy-DbaLinkedServer.ps1
+26-4Lines changed: 26 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ function Copy-DbaLinkedServer {
8
8
9
9
This is particularly useful during server migrations, disaster recovery scenarios, or when consolidating environments where maintaining external data connections is critical. The function handles various provider types and can optionally upgrade older SQL Client providers to current versions during migration.
10
10
11
+
When upgrading from older versions to SQL Server 2025+, MSOLEDBSQL is changed to MSOLEDBSQL19 and provider string for encrypt and trustservercertificate settings is added if not already included to ensure compatibility with the breaking changes in the new driver.
12
+
11
13
Credit: Password decryption techniques provided by Antti Rantasaari (NetSPI, 2014) - https://blog.netspi.com/decrypting-mssql-database-link-server-passwords/
12
14
13
15
.PARAMETERSource
@@ -179,8 +181,8 @@ function Copy-DbaLinkedServer {
@@ -192,7 +194,12 @@ function Copy-DbaLinkedServer {
192
194
193
195
# This does a check to warn of missing OleDbProviderSettings but should only be checked on SQL on Windows
194
196
if ($destServer.Settings.OleDbProviderSettings.Name.Length-ne0) {
195
-
if (!$destServer.Settings.OleDbProviderSettings.Name-contains$provider-and!$provider.StartsWith("SQLN")) {
197
+
if ($destServer.VersionMajor-ge17-and$provider-eq"MSOLEDBSQL") {
198
+
# 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.
199
+
Write-Message-Level Verbose -Message "Upgrading provider from MSOLEDBSQL to MSOLEDBSQL19 to ensure compatibility with SQL Server 2025+."
200
+
$provider="MSOLEDBSQL19"
201
+
}
202
+
if (-not ($destServer.Settings.OleDbProviderSettings.Name-contains$provider) -and-not ($provider.StartsWith("SQLN"))) {
196
203
if ($Pscmdlet.ShouldProcess($destinstance,"$($destServer.Name) does not support the $provider provider. Skipping $linkedServerName.")) {
197
204
$copyLinkedServer.Status="Skipped"
198
205
$copyLinkedServer.Notes="Missing provider"
@@ -246,7 +253,22 @@ function Copy-DbaLinkedServer {
246
253
$sql=$sql-replace ("sqlncli[0-9]+",$newProvider)
247
254
}
248
255
249
-
$destServer.Query($sql)
256
+
if ($provider-eq"MSOLEDBSQL19") {
257
+
# 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.
if ($providerString-notmatch"Encrypt\s*=\s*Optional"-and$providerString-notmatch"TrustServerCertificate\s*=\s*Yes") {
261
+
Write-Message-Level Warning -Message "Provider string currently set to '$providerString', so will not change it. Please verify that it includes 'Encrypt=Optional;TrustServerCertificate=Yes' to ensure connectivity."
262
+
} else {
263
+
Write-Message-Level Verbose -Message "Provider string already includes encrypt and trustservercertificate settings, so not modifying it."
264
+
}
265
+
} else {
266
+
Write-Message-Level Verbose -Message "Provider string is empty. Adding 'Encrypt=Optional;TrustServerCertificate=Yes' to provider string for MSOLEDBSQL19."
0 commit comments