Skip to content

Commit c0dab1c

Browse files
author
Davoud Eshtehari
committed
Merge remote-tracking branch 'UpStream/main' into GHIssue/DecimalConversion_Issue#95
2 parents 98ad6a1 + 83b8421 commit c0dab1c

File tree

67 files changed

+3001
-2753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3001
-2753
lines changed

porting-cheat-sheet.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ For .NET Framework projects it may be necessary to include the following in your
3131
</configuration>
3232
```
3333

34+
## Functionality Changes
35+
36+
| System.Data.SqlClient | Microsoft.Data.SqlClient |
37+
|--|--|
38+
| Can use DateTime object as value for SqlParameter with type `DbType.Time`. | Must use TimeSpan object as value for SqlParameter with type `DbType.Time`. |
39+
| Using DateTime object as value for SqlParameter with type `DbType.Date` would send date and time to SQL Server. | DateTime object's time components will be truncated when sent to SQL Server using `DbType.Date`. |
40+
3441
## Contribute to this Cheat Sheet
3542

3643
We would love the SqlClient community to help enhance this cheat sheet by contributing experiences and challenges faced when porting their applications.

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ abstract public DbProviderFactory ProviderFactory
4949

5050
public void ClearAllPools()
5151
{
52-
long scopeID = SqlClientEventSource.Log.TryScopeEnterEvent("<prov.DbConnectionFactory.ClearAllPools|API");
53-
try
52+
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearAllPools|API"))
5453
{
5554
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
5655
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
@@ -62,48 +61,33 @@ public void ClearAllPools()
6261
}
6362
}
6463
}
65-
finally
66-
{
67-
SqlClientEventSource.Log.TryScopeLeaveEvent(scopeID);
68-
}
6964
}
7065

7166
public void ClearPool(DbConnection connection)
7267
{
7368
ADP.CheckArgumentNull(connection, nameof(connection));
74-
long scopeID = SqlClientEventSource.Log.TryScopeEnterEvent("<prov.DbConnectionFactory.ClearPool|API> {0}", GetObjectId(connection));
75-
try
69+
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearPool|API> {0}", GetObjectId(connection)))
7670
{
7771
DbConnectionPoolGroup poolGroup = GetConnectionPoolGroup(connection);
7872
if (null != poolGroup)
7973
{
8074
poolGroup.Clear();
8175
}
8276
}
83-
finally
84-
{
85-
SqlClientEventSource.Log.TryScopeLeaveEvent(scopeID);
86-
}
8777
}
8878

8979
public void ClearPool(DbConnectionPoolKey key)
9080
{
9181
Debug.Assert(key != null, "key cannot be null");
9282
ADP.CheckArgumentNull(key.ConnectionString, nameof(key) + "." + nameof(key.ConnectionString));
93-
long scopeID = SqlClientEventSource.Log.TryScopeEnterEvent("<prov.DbConnectionFactory.ClearPool|API> connectionString");
94-
try
83+
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearPool|API> connectionString"))
9584
{
96-
DbConnectionPoolGroup poolGroup;
9785
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
98-
if (connectionPoolGroups.TryGetValue(key, out poolGroup))
86+
if (connectionPoolGroups.TryGetValue(key, out DbConnectionPoolGroup poolGroup))
9987
{
10088
poolGroup.Clear();
10189
}
10290
}
103-
finally
104-
{
105-
SqlClientEventSource.Log.TryScopeLeaveEvent(scopeID);
106-
}
10791
}
10892

10993
internal virtual DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions)

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@
534534
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIMarsQueuedPacket.cs" />
535535
<Compile Include="Microsoft\Data\SqlClient\SNI\SNINpHandle.cs" />
536536
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPacket.cs" />
537+
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPacket.Debug.cs" />
537538
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPacketPool.cs" />
538539
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPhysicalHandle.cs" />
539540
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIProxy.cs" />

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Windows.cs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Microsoft.Data.SqlClient.SNI
1313
internal sealed class LocalDB
1414
{
1515
private static readonly LocalDB Instance = new LocalDB();
16-
private const string s_className = nameof(LocalDB);
1716

1817
//HKEY_LOCAL_MACHINE
1918
private const string LocalDBInstalledVersionRegistryKey = "SOFTWARE\\Microsoft\\Microsoft SQL Server Local DB\\Installed Versions\\";
@@ -103,8 +102,7 @@ internal static string MapLocalDBErrorStateToErrorMessage(LocalDBErrorState erro
103102
/// </summary>
104103
private bool LoadUserInstanceDll()
105104
{
106-
long scopeID = SqlClientEventSource.Log.TrySNIScopeEnterEvent(s_className);
107-
try
105+
using (TrySNIEventScope.Create(nameof(LocalDB)))
108106
{
109107
// Check in a non thread-safe way if the handle is already set for performance.
110108
if (_sqlUserInstanceLibraryHandle != null)
@@ -128,15 +126,15 @@ private bool LoadUserInstanceDll()
128126
if (dllPath == null)
129127
{
130128
SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState));
131-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "User instance DLL path is null.");
129+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is null.");
132130
return false;
133131
}
134132

135133
// In case the registry had an empty path for dll
136134
if (string.IsNullOrWhiteSpace(dllPath))
137135
{
138136
SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55);
139-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "User instance DLL path is invalid. DLL path = {0}", dllPath);
137+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is invalid. DLL path = {0}", dllPath);
140138
return false;
141139
}
142140

@@ -146,7 +144,7 @@ private bool LoadUserInstanceDll()
146144
if (libraryHandle.IsInvalid)
147145
{
148146
SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56);
149-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "Library Handle is invalid. Could not load the dll.");
147+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Library Handle is invalid. Could not load the dll.");
150148
libraryHandle.Dispose();
151149
return false;
152150
}
@@ -157,7 +155,7 @@ private bool LoadUserInstanceDll()
157155
if (_startInstanceHandle == IntPtr.Zero)
158156
{
159157
SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57);
160-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "Was not able to load the PROC from DLL. Bad Runtime.");
158+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Was not able to load the PROC from DLL. Bad Runtime.");
161159
libraryHandle.Dispose();
162160
return false;
163161
}
@@ -174,14 +172,10 @@ private bool LoadUserInstanceDll()
174172
}
175173

176174
_sqlUserInstanceLibraryHandle = libraryHandle;
177-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.INFO, "User Instance DLL was loaded successfully.");
175+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.INFO, "User Instance DLL was loaded successfully.");
178176
return true;
179177
}
180178
}
181-
finally
182-
{
183-
SqlClientEventSource.Log.TrySNIScopeLeaveEvent(scopeID);
184-
}
185179
}
186180

187181
/// <summary>
@@ -191,16 +185,15 @@ private bool LoadUserInstanceDll()
191185
/// <returns></returns>
192186
private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
193187
{
194-
long scopeID = SqlClientEventSource.Log.TrySNIScopeEnterEvent(s_className);
195-
try
188+
using (TrySNIEventScope.Create(nameof(LocalDB)))
196189
{
197190
string dllPath = null;
198191
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(LocalDBInstalledVersionRegistryKey))
199192
{
200193
if (key == null)
201194
{
202195
errorState = LocalDBErrorState.NO_INSTALLATION;
203-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "No installation found.");
196+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "No installation found.");
204197
return null;
205198
}
206199

@@ -215,7 +208,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
215208
if (!Version.TryParse(subKey, out currentKeyVersion))
216209
{
217210
errorState = LocalDBErrorState.INVALID_CONFIG;
218-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "Invalid Configuration.");
211+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Invalid Configuration.");
219212
return null;
220213
}
221214

@@ -229,7 +222,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
229222
if (latestVersion.Equals(zeroVersion))
230223
{
231224
errorState = LocalDBErrorState.INVALID_CONFIG;
232-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "Invalid Configuration.");
225+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Invalid Configuration.");
233226
return null;
234227
}
235228

@@ -242,7 +235,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
242235
if (instanceAPIPathRegistryObject == null)
243236
{
244237
errorState = LocalDBErrorState.NO_SQLUSERINSTANCEDLL_PATH;
245-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "No SQL user instance DLL. Instance API Path Registry Object Error.");
238+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "No SQL user instance DLL. Instance API Path Registry Object Error.");
246239
return null;
247240
}
248241

@@ -251,7 +244,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
251244
if (valueKind != RegistryValueKind.String)
252245
{
253246
errorState = LocalDBErrorState.INVALID_SQLUSERINSTANCEDLL_PATH;
254-
SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.ERR, "Invalid SQL user instance DLL path. Registry value kind mismatch.");
247+
SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Invalid SQL user instance DLL path. Registry value kind mismatch.");
255248
return null;
256249
}
257250

@@ -262,10 +255,6 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
262255
}
263256
}
264257
}
265-
finally
266-
{
267-
SqlClientEventSource.Log.TrySNIScopeLeaveEvent(scopeID);
268-
}
269258
}
270259
}
271260
}

0 commit comments

Comments
 (0)