@@ -116,48 +116,6 @@ $dddafter-$dddbefore
116
116
}
117
117
}
118
118
119
- Function Get-SqlConnectionString
120
- {
121
- [CmdletBinding ()]
122
- param (
123
- [Parameter (Mandatory = $true )][ValidateNotNullOrEmpty ()][string ] $ServerName ,
124
- [Parameter (Mandatory = $true )][ValidateNotNullOrEmpty ()][string ] $Login ,
125
- [Parameter (Mandatory = $true )][ValidateNotNullOrEmpty ()][string ] $DatabaseName
126
- );
127
-
128
- $ServerNameTrimmed = $ServerName.Trim ();
129
- $LoginTrimmed = $Login.Trim ();
130
-
131
- <#
132
- ☹️
133
- This is so questionable, but it looks like sqlpackage cannot handle valid connection strings that use a valid server alias.
134
- The following snippet is meant to spelunk through the registry and extract the actual server from the alias.
135
- ☹️
136
- #>
137
- $resolvedServerName = $ServerNameTrimmed ;
138
- $serverAlias = Get-Item - Path HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo - ErrorAction SilentlyContinue;
139
- if ($null -ne $serverAlias -And $serverAlias.GetValueNames () -contains $ServerNameTrimmed ) {
140
- $aliasValue = $serverAlias.GetValue ($ServerNameTrimmed )
141
- if ($aliasValue -match " DBMSSOCN[,](.*)" ){
142
- $resolvedServerName = $Matches [1 ];
143
- }
144
- }
145
-
146
- <# When using Windows Authentication, you must use "Integrated Security=SSPI" in the SqlConnectionString. Else use "User ID=<username>;Password=<password>;" #>
147
- if ($LoginTrimmed -match ' ((.*[-][uU])|(.*[-][pP]))+.*' ){
148
- $AuthenticationString = $LoginTrimmed -replace ' ^((\s*[-][uU]\s+(?<user>\S+)\s*)|(\s*[-][pP]\s+)((?<quote>['' "])(?<password>.*?)\k<quote>|(?<password>\S+))\s*)+$' , ' User Id=${user};Password="${password}"'
149
- }
150
- elseif ($LoginTrimmed -eq " -E" ){
151
- $AuthenticationString = " Integrated Security=SSPI;" ;
152
- }
153
- else {
154
- throw $LoginTrimmed + " is not supported here."
155
- }
156
-
157
- $SqlConnectionString = " Data Source=" + $resolvedServerName + " ;" + $AuthenticationString + " ;Connect Timeout=60;Initial Catalog=" + $DatabaseName + " ;TrustServerCertificate=true;" ;
158
- $SqlConnectionString ;
159
- }
160
-
161
119
function Get-TempFileForQuery {
162
120
[CmdletBinding ()]
163
121
[OutputType ([string ])]
0 commit comments