From 2dcfd5dca6e23eef07f06970f6fc47d6354a3c49 Mon Sep 17 00:00:00 2001 From: Amir Shitrit Date: Wed, 20 Mar 2024 18:29:46 +0200 Subject: [PATCH 1/2] Switch from System.Data.SqlClient to Microsoft.Data.SqlClient per official recommendation --- .../Proto.Persistence.SqlServer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Proto.Persistence.SqlServer/Proto.Persistence.SqlServer.csproj b/src/Proto.Persistence.SqlServer/Proto.Persistence.SqlServer.csproj index f985e090db..86c0dca169 100644 --- a/src/Proto.Persistence.SqlServer/Proto.Persistence.SqlServer.csproj +++ b/src/Proto.Persistence.SqlServer/Proto.Persistence.SqlServer.csproj @@ -4,7 +4,7 @@ - + From a5a81d162f785e4141fa3afaa7f9c989f2cbd1d2 Mon Sep 17 00:00:00 2001 From: Amir Shitrit Date: Wed, 20 Mar 2024 18:29:59 +0200 Subject: [PATCH 2/2] use await on using --- src/Proto.Persistence.SqlServer/SqlServerProvider.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Proto.Persistence.SqlServer/SqlServerProvider.cs b/src/Proto.Persistence.SqlServer/SqlServerProvider.cs index b60272711a..d47c70faca 100644 --- a/src/Proto.Persistence.SqlServer/SqlServerProvider.cs +++ b/src/Proto.Persistence.SqlServer/SqlServerProvider.cs @@ -1,7 +1,7 @@ using System; using System.Data; -using System.Data.SqlClient; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; using Newtonsoft.Json; using static System.Data.SqlDbType; @@ -55,8 +55,7 @@ public SqlServerProvider( _sqlDeleteSnapshots = $@"DELETE FROM [{_tableSchema}].[{_tableSnapshots}] WHERE ActorName = @ActorName AND SnapshotIndex <= @SnapshotIndex"; - _sqlReadEvents = - $@"SELECT EventIndex, EventData FROM [{_tableSchema}].[{_tableEvents}] WHERE ActorName = @ActorName AND EventIndex >= @IndexStart AND EventIndex <= @IndexEnd ORDER BY EventIndex ASC"; + _sqlReadEvents = $@"SELECT EventIndex, EventData FROM [{_tableSchema}].[{_tableEvents}] WHERE ActorName = @ActorName AND EventIndex >= @IndexStart AND EventIndex <= @IndexEnd ORDER BY EventIndex ASC"; _sqlReadSnapshot = $@"SELECT TOP 1 SnapshotIndex, SnapshotData FROM [{_tableSchema}].[{_tableSnapshots}] WHERE ActorName = @ActorName ORDER BY SnapshotIndex DESC"; @@ -84,9 +83,9 @@ public Task DeleteSnapshotsAsync(string actorName, long inclusiveToIndex) => public async Task GetEventsAsync(string actorName, long indexStart, long indexEnd, Action callback) { - using var connection = new SqlConnection(_connectionString); + await using var connection = new SqlConnection(_connectionString); - using var command = new SqlCommand(_sqlReadEvents, connection); + await using var command = new SqlCommand(_sqlReadEvents, connection); await connection.OpenAsync().ConfigureAwait(false);