現在我的問題與sqlBulkCopy是,它完成沒有任何錯誤,但當我看着表,我看不到任何數據。當它不返回任何錯誤時調試SqlBulkCopy問題
try catch塊沒有發現錯誤,我錯過了什麼?因爲我不看我的代碼
任何問題,這是我使用的代碼:
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Buying ID", typeof(string)));
table.Columns.Add(new DataColumn("Buying BPC ID", typeof(string)));
table.Columns.Add(new DataColumn("Buying BP Name", typeof(string)));
table.Columns.Add(new DataColumn("Buying BP Post Code", typeof(string)));
... snip ...
table.Columns.Add(new DataColumn("Buyer BP Type", typeof(string)));
table.Columns.Add(new DataColumn("Seller BP Type", typeof(string)));
table.Columns.Add(new DataColumn("FileSource", typeof(string)));
table.Columns.Add(new DataColumn("ImportDate", typeof(System.DateTime)));
while ((line = sr.ReadLine()) != null)
{
string[] data = line.Split('\t');
DataRow row = table.NewRow();
for (int i=0; i<data.Length; i++)
{
row[i] = data[i];
}
row["FileSource"] = fi.Name;
row["ImportDate"] = DateTime.Now;
}
try
{
db.Connection.Open();
SqlBulkCopy bulkcopy = new SqlBulkCopy(db.Connection);
bulkcopy.BatchSize = 500;
bulkcopy.BulkCopyTimeout = 600;
bulkcopy.DestinationTableName = "dbo.LNST_test";
foreach (var col in table.Columns)
{
bulkcopy.ColumnMappings.Add(col.ToString(), col.ToString()); //col names in datatable are identical to col names in database
}
bulkcopy.WriteToServer(table);
db.Connection.Close();
}
catch (Exception e)
{
Console.WriteLine("ERROR : "+e.Message);
}
可能是交易問題?什麼是分貝? –
無論是事務處理還是表中沒有行,或者您正在SSMS中查看錯誤的表。 – usr
數據庫是MSSQL 2008,我以管理員身份連接到它(它只是一個測試數據庫)而沒有其他人。所以我不認爲這是一個交易的問題:( – Gabriel