1818using System.Xml;
1919using Interop.Common.Sni;
2020using Microsoft.Data.Common;
21+ using Microsoft.Data.Common.ConnectionString;
2122using Microsoft.Data.ProviderBase;
2223using Microsoft.Data.Sql;
2324using Microsoft.Data.SqlClient.Connection;
2425using Microsoft.Data.SqlClient.DataClassification;
2526using Microsoft.Data.SqlClient.LocalDb;
2627using Microsoft.Data.SqlClient.Server;
27- using Microsoft.Data.SqlClient.UserAgent;
2828using Microsoft.Data.SqlClient.Utilities;
2929using Microsoft.SqlServer.Server;
3030
@@ -1317,11 +1317,11 @@ internal void TdsLogin(
13171317 // length in bytes
13181318 int length = TdsEnums.SQL2005_LOG_REC_FIXED_LEN;
13191319
1320- string clientInterfaceName = TdsEnums.SQL_PROVIDER_NAME;
1321- Debug.Assert(TdsEnums.MAXLEN_CLIENTINTERFACE >= clientInterfaceName.Length, "cchCltIntName can specify at most 128 unicode characters. See Tds spec");
1320+ // Obtain the client interface name.
1321+ string clientInterfaceName = DbConnectionStringDefaults.ApplicationName;
1322+ Debug.Assert(clientInterfaceName.Length <= TdsEnums.MAXLEN_CLIENTINTERFACE);
13221323
13231324 // add up variable-len portions (multiply by 2 for byte len of char strings)
1324- //
13251325 checked
13261326 {
13271327 length += (rec.hostName.Length + rec.applicationName.Length +
@@ -1376,7 +1376,7 @@ internal void TdsLogin(
13761376 requestedFeatures,
13771377 recoverySessionData,
13781378 fedAuthFeatureExtensionData,
1379- UserAgentInfo.UserAgentCachedJsonPayload.ToArray() ,
1379+ UserAgent.Ucs2Bytes ,
13801380 useFeatureExt,
13811381 length
13821382 );
@@ -9186,43 +9186,41 @@ internal int WriteVectorSupportFeatureRequest(bool write)
91869186 }
91879187
91889188 /// <summary>
9189- /// Writes the User Agent feature request to the physical state object.
9190- /// The request includes the feature ID, feature data length, version number and encoded JSON payload.
9189+ /// Writes the User Agent feature request to the physical state
9190+ /// object. The request includes the feature ID, feature data length,
9191+ /// and UCS-2 little-endian encoded payload.
91919192 /// </summary>
9192- /// <param name="userAgentJsonPayload"> Byte array of UTF-8 encoded JSON payload for User Agent</param>
9193+ /// <remarks>
9194+ /// The feature request consists of:
9195+ /// - 1 byte for the feature ID.
9196+ /// - 4 bytes for the feature data length.
9197+ /// - N bytes for the UCS-2 payload
9198+ /// </remarks>
9199+ /// <param name="userAgent">
9200+ /// UCS-2 little-endian encoded UserAgent payload.
9201+ /// </param>
91939202 /// <param name="write">
9194- /// If true, writes the feature request to the physical state object.
9195- /// If false, just calculates the length.
9203+ /// If true, writes the feature request to the physical state object.
9204+ /// If false, just calculates the length.
91969205 /// </param>
91979206 /// <returns>The length of the feature request in bytes.</returns>
9198- /// <remarks>
9199- /// The feature request consists of:
9200- /// - 1 byte for the feature ID.
9201- /// - 4 bytes for the feature data length.
9202- /// - 1 byte for the version number.
9203- /// - N bytes for the JSON payload
9204- /// </remarks>
9205- internal int WriteUserAgentFeatureRequest(byte[] userAgentJsonPayload,
9207+ internal int WriteUserAgentFeatureRequest(ReadOnlyMemory<byte> userAgent,
92069208 bool write)
92079209 {
9208- // 1byte (Feature Version) + size of UTF-8 encoded JSON payload
9209- int dataLen = 1 + userAgentJsonPayload.Length;
9210- // 1byte (Feature ID) + 4bytes (Feature Data Length) + 1byte (Version) + N(JSON payload size)
9211- int totalLen = 1 + 4 + dataLen;
9210+ // 1 byte (Feature ID) + 4 bytes (Feature Data Length) + N bytes
9211+ // (UCS-2 payload size)
9212+ int totalLen = 1 + 4 + userAgent.Length;
92129213
92139214 if (write)
92149215 {
92159216 // Write Feature ID
92169217 _physicalStateObj.WriteByte(TdsEnums.FEATUREEXT_USERAGENT);
92179218
92189219 // Feature Data Length
9219- WriteInt(dataLen, _physicalStateObj);
9220-
9221- // Write Feature Version
9222- _physicalStateObj.WriteByte(TdsEnums.SUPPORTED_USER_AGENT_VERSION);
9220+ WriteInt(userAgent.Length, _physicalStateObj);
92239221
9224- // Write encoded JSON payload
9225- _physicalStateObj.WriteByteArray(userAgentJsonPayload, userAgentJsonPayload.Length, 0 );
9222+ // Write encoded UCS-2 payload
9223+ _physicalStateObj.WriteByteSpan(userAgent.Span );
92269224 }
92279225
92289226 return totalLen;
@@ -9502,7 +9500,7 @@ private void WriteLoginData(SqlLogin rec,
95029500 requestedFeatures,
95039501 recoverySessionData,
95049502 fedAuthFeatureExtensionData,
9505- UserAgentInfo.UserAgentCachedJsonPayload.ToArray() ,
9503+ UserAgent.Ucs2Bytes ,
95069504 useFeatureExt,
95079505 length,
95089506 true
@@ -9525,7 +9523,7 @@ private void WriteLoginData(SqlLogin rec,
95259523 private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
95269524 SessionData recoverySessionData,
95279525 FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData,
9528- byte[] userAgentJsonPayload ,
9526+ ReadOnlyMemory< byte> userAgent ,
95299527 bool useFeatureExt,
95309528 int length,
95319529 bool write = false)
@@ -9537,7 +9535,7 @@ private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
95379535 // NOTE: As part of TDS spec UserAgent feature extension should be the first feature extension in the list.
95389536 if (LocalAppContextSwitches.EnableUserAgent && ((requestedFeatures & TdsEnums.FeatureExtension.UserAgent) != 0))
95399537 {
9540- length += WriteUserAgentFeatureRequest(userAgentJsonPayload , write);
9538+ length += WriteUserAgentFeatureRequest(userAgent , write);
95419539 }
95429540 if ((requestedFeatures & TdsEnums.FeatureExtension.SessionRecovery) != 0)
95439541 {
0 commit comments