Skip to content

Commit

Permalink
Fix sql syntax and reader open errors (#1145)
Browse files Browse the repository at this point in the history
* Fix add column sql server syntax

* Fix There is already an open DataReader error

---------

Co-authored-by: Kristian Kadlec <[email protected]>
  • Loading branch information
ChrisKrikade and Kristian Kadlec authored Feb 24, 2025
1 parent 52e947a commit be0a83e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MimeKit/Cryptography/SQLServerCertificateDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override void AddTableColumn (DbConnection connection, DataTable table
int primaryKeys = table.PrimaryKey?.Length ?? 0;

statement.Append (table.TableName);
statement.Append (" ADD COLUMN ");
statement.Append (" ADD ");
Build (statement, table, column, ref primaryKeys);

using (var command = CreateCommand ()) {
Expand Down
5 changes: 3 additions & 2 deletions MimeKit/Cryptography/SqlCertificateDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using Org.BouncyCastle.X509.Store;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities.Collections;
using System.Linq;

namespace MimeKit.Cryptography {
/// <summary>
Expand Down Expand Up @@ -288,7 +289,7 @@ void CreateCertificatesTable (DbConnection connection, DataTable table)
column = table.Columns[table.Columns.IndexOf (CertificateColumnNames.SubjectDnsNames)];
AddTableColumn (connection, table, column);

foreach (var record in Find (null, false, X509CertificateRecordFields.Id | X509CertificateRecordFields.Certificate)) {
foreach (var record in Find (null, false, X509CertificateRecordFields.Id | X509CertificateRecordFields.Certificate).ToArray()) {
var statement = $"UPDATE {CertificatesTableName} SET {CertificateColumnNames.Anchor} = @ANCHOR, {CertificateColumnNames.SubjectName} = @SUBJECTNAME, {CertificateColumnNames.SubjectKeyIdentifier} = @SUBJECTKEYIDENTIFIER, {CertificateColumnNames.SubjectEmail} = @SUBJECTEMAIL, {CertificateColumnNames.SubjectDnsNames} = @SUBJECTDNSNAMES WHERE {CertificateColumnNames.Id} = @ID";

using (var command = CreateCommand ()) {
Expand Down Expand Up @@ -318,7 +319,7 @@ void CreateCertificatesTable (DbConnection connection, DataTable table)
var column = table.Columns[table.Columns.IndexOf (CertificateColumnNames.SubjectDnsNames)];
AddTableColumn (connection, table, column);

foreach (var record in Find (null, false, X509CertificateRecordFields.Id | X509CertificateRecordFields.Certificate)) {
foreach (var record in Find (null, false, X509CertificateRecordFields.Id | X509CertificateRecordFields.Certificate).ToArray()) {
var statement = $"UPDATE {CertificatesTableName} SET {CertificateColumnNames.SubjectEmail} = @SUBJECTEMAIL, {CertificateColumnNames.SubjectDnsNames} = @SUBJECTDNSNAMES WHERE {CertificateColumnNames.Id} = @ID";

using (var command = CreateCommand ()) {
Expand Down

0 comments on commit be0a83e

Please sign in to comment.