SqlExpressデータベースのコードから実行するときにSqlBulkCopyを使用する際の問題を知っている人はいますか?
SQLServer2008の完全なインスタンスとSQLServer2008Expressのインスタンスがあります。サーバーにインストールされたフルインスタンスと、テストマシンにローカルにインストールされたエクスプレスインスタンス。サーバー接続文字列を使用してアプリケーション(次のコードを使用)を実行すると、正常に実行され、新しく挿入された行と情報メッセージが表示されます。しかし、Local Sql Express接続文字列を使用してアプリケーションを実行すると、何も起こらず、メッセージやテーブル行が挿入されません。これは、テストマシン(SQL Expressを実行しているのと同じマシン)にインストールされているデスクトップアプリケーションです。
これは、すべてtry catchブロックに含まれているため、本当に困惑していますが、例外はスローされていません。実行されないようです。お知らせ下さい!ありがとう
これが私のコードです:
public static bool BulkInsertReminders(DataTable dtReminders)
{
bool success = false;
string sql = "user id=" + DBEntries.DBUser + ";password=" + DBEntries.DBPassword + ";server=" + DBEntries.DBHost + ";database=" + DBEntries.LocalDB + ";Encrypt=YES;TrustServerCertificate=true";
MessageBox.Show("Insert Rows Count: " + dtReminders.Rows.Count);
using (SqlConnection msSQL = new SqlConnection(sql))
{
SqlTransaction copy = null;
SqlCommand commandRowCount = new SqlCommand("SELECT COUNT(*) FROM " + "dbo.reminders", msSQL);
try
{
msSQL.Open();
copy = msSQL.BeginTransaction();
using (SqlBulkCopy load = new SqlBulkCopy(msSQL, SqlBulkCopyOptions.TableLock, copy))
{
load.BulkCopyTimeout = 15;
load.ColumnMappings.Add("reminder_id", "reminder_id");
load.ColumnMappings.Add("creation_date", "creation_date");
load.ColumnMappings.Add("created_by", "created_by");
load.ColumnMappings.Add("sent", "sent");
load.ColumnMappings.Add("sent_by", "sent_by");
load.ColumnMappings.Add("sent_date", "sent_date");
load.DestinationTableName = "dbo.reminders";
load.WriteToServer(dtReminders);
success = true;
commandRowCount.Transaction = copy;
int totalRows = Convert.ToInt32(commandRowCount.ExecuteScalar());
MessageBox.Show("New Table Row Count: " + totalRows + Environment.NewLine + "Rows Before Insert: " + (totalRows - dtReminders.Rows.Count));
}
}
catch (Exception exc)
{
MessageBox.Show("Error - Issues adding reminders information to database.", "Contact Support");
email err = new email();
err.sendErrorEmail(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name.ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), exc.Message, exc.Data, exc.StackTrace);
success = false;
copy.Rollback();
}
}
return success;
}