Skip to content

Commit

Permalink
Remove Microsoft.SqlServer.SqlManagementObjects dependency (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
IGx89 authored May 3, 2022
1 parent e1f9085 commit a68c91a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/DurableTask.SqlServer/DurableTask.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.*" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="161.46041.41" />
<PackageReference Include="SemanticVersion" Version="2.1.0" />
<PackageReference Include="System.Threading.Channels" Version="4.7.1" />
</ItemGroup>
Expand Down
19 changes: 11 additions & 8 deletions src/DurableTask.SqlServer/SqlDbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace DurableTask.SqlServer
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using SemVersion;

class SqlDbManager
Expand Down Expand Up @@ -219,7 +218,6 @@ async Task<bool> CreateDatabaseAsync(string databaseName, SqlConnection connecti

async Task ExecuteSqlScriptAsync(string scriptName, DatabaseLock dbLock)
{
// We don't actually use the lock here, but want to make sure the caller is holding it.
if (dbLock == null)
{
throw new ArgumentNullException(nameof(dbLock));
Expand All @@ -230,17 +228,22 @@ async Task ExecuteSqlScriptAsync(string scriptName, DatabaseLock dbLock)
throw new ArgumentException("This database lock has already been released!", nameof(dbLock));
}

string schemaCommands = await GetScriptTextAsync(scriptName);
string scriptText = await GetScriptTextAsync(scriptName);

// Reference: https://stackoverflow.com/questions/650098/how-to-execute-an-sql-script-file-using-c-sharp
using SqlConnection scriptRunnerConnection = this.settings.CreateConnection();
var serverConnection = new ServerConnection(scriptRunnerConnection);
// Split script into distinct executeable commands
IEnumerable<string> scriptCommands = Regex.Split(scriptText, @"^\s*GO\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase)
.Where(x => x.Trim().Length > 0);

Stopwatch latencyStopwatch = Stopwatch.StartNew();
try
{
// NOTE: Async execution is not supported by this library
serverConnection.ExecuteNonQuery(schemaCommands);
foreach (string commandText in scriptCommands)
{
using SqlCommand command = dbLock.CreateCommand();
command.CommandText = commandText;

await command.ExecuteNonQueryAsync();
}
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="6.0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.*" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="161.47008.0" />
<PackageReference Include="Moq" Version="4.16.*" />
<PackageReference Include="xunit" Version="2.4.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.*" />
Expand Down

0 comments on commit a68c91a

Please sign in to comment.