[英]Transfer from MsSQL to MySQL error
Im trying to transfer data between databases (from MsSQL Server to MySQL). 我试图在数据库之间传输数据(从MsSQL Server到MySQL)。 Source database has ~2700 records. 源数据库有约2700条记录。 And when im executing program, every 400-600 record VS throws an exception: 当我执行程序时,每400-600条记录VS都会引发一个异常:
Invalid attempt to call IsDBNull when reader is closed. 关闭阅读器时,无效的调用IsDBNull的尝试。
Code: 码:
foreach (var product in products)
{
var prd = product;
var cmd = connection.CreateCommand();
cmd.CommandText =
"INSERT INTO Product(CategoryID, Position, PresentItemID, Guid, ThumbX, ThumbY, " +
"ImgX, ImgY, Name, Description, IsAvailable, TotalStock, Price, ListPrice, Size, " +
"meta_tag, desc_tag, page_metatags, FreeDescription, IsVintage, OnSale, Valentine)" +
"VALUES(@CategoryID, @Position, @PresentItemID, @Guid, @ThumbX, @ThumbY, " +
"@ImgX, @ImgY, @Name, @Description, @IsAvailable, @TotalStock, @Price, @ListPrice, @Size, " +
"@meta_tag, @desc_tag, @page_metatags, @FreeDescription, @IsVintage, @OnSale, @Valentine)";
cmd.Parameters.AddWithValue("@CategoryID", prd.CategoryID);
cmd.Parameters.AddWithValue("@Position", prd.Position);
cmd.Parameters.AddWithValue("@PresentItemID", prd.PresentItemID);
cmd.Parameters.AddWithValue("@Guid", prd.Guid);
...
cmd.Parameters.AddWithValue("@IsVintage", prd.IsVintage);
cmd.Parameters.AddWithValue("@OnSale", prd.OnSale);
cmd.Parameters.AddWithValue("@Valentine", prd.Valentine);
cmd.ExecuteNonQuery();
progressBar1.PerformStep();
}
I tried to add this code 我试图添加此代码
List<Product> prd = products.ToList();
and transfer data from list, not directly from database, but had same error. 并从列表中传输数据,而不是直接从数据库中传输数据,但是存在相同的错误。
Thanks for help. 感谢帮助。
var cmd = connection.CreateCommand(); var cmd = connection.CreateCommand();
You probably need to properly dispose the object being created: 您可能需要正确处理要创建的对象:
using(var cmd = connection.CreateCommand()) { cmd.CommandText = ... }
To resolve this problem I created back-up of source database, and installed it on machine with destination database. 为了解决此问题,我创建了源数据库的备份,并将其安装在具有目标数据库的计算机上。 Then programm was executed without any problems. 然后程序被执行而没有任何问题。 Still cant realize why this exception happened to me. 仍然不明白为什么这个例外发生在我身上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.