@@ -1856,11 +1856,36 @@ private void ResolveExtendedServerName(ServerInfo serverInfo, bool aliasLookup,
1856
1856
string host = serverInfo . UserServerName ;
1857
1857
string protocol = serverInfo . UserProtocol ;
1858
1858
1859
- //TODO: fix local host enforcement with datadirectory and failover
1860
- if ( options . EnforceLocalHost )
1861
- {
1862
- // verify LocalHost for |DataDirectory| usage
1863
- SqlConnectionString . VerifyLocalHostAndFixup ( ref host , true , true /*fix-up to "."*/ ) ;
1859
+ if ( aliasLookup )
1860
+ { // We skip this for UserInstances...
1861
+ // Perform registry lookup to see if host is an alias. It will appropriately set host and protocol, if an Alias.
1862
+ // Check if it was already resolved, during CR reconnection _currentSessionData values will be copied from
1863
+ // _reconnectSessonData of the previous connection
1864
+ if ( _currentSessionData != null && ! string . IsNullOrEmpty ( host ) )
1865
+ {
1866
+ Tuple < string , string > hostPortPair ;
1867
+ if ( _currentSessionData . _resolvedAliases . TryGetValue ( host , out hostPortPair ) )
1868
+ {
1869
+ host = hostPortPair . Item1 ;
1870
+ protocol = hostPortPair . Item2 ;
1871
+ }
1872
+ else
1873
+ {
1874
+ TdsParserStaticMethods . AliasRegistryLookup ( ref host , ref protocol ) ;
1875
+ _currentSessionData . _resolvedAliases . Add ( serverInfo . UserServerName , new Tuple < string , string > ( host , protocol ) ) ;
1876
+ }
1877
+ }
1878
+ else
1879
+ {
1880
+ TdsParserStaticMethods . AliasRegistryLookup ( ref host , ref protocol ) ;
1881
+ }
1882
+
1883
+ //TODO: fix local host enforcement with datadirectory and failover
1884
+ if ( options . EnforceLocalHost )
1885
+ {
1886
+ // verify LocalHost for |DataDirectory| usage
1887
+ SqlConnectionString . VerifyLocalHostAndFixup ( ref host , true , true /*fix-up to "."*/ ) ;
1888
+ }
1864
1889
}
1865
1890
1866
1891
serverInfo . SetDerivedNames ( protocol , host ) ;
0 commit comments