gpt4 book ai didi

.net - 需要帮助来调试使用 .Net 和 MySQL 的应用程序

转载 作者:行者123 更新时间:2023-11-29 01:01:52 24 4
gpt4 key购买 nike

在使用 .Net 将数据插入 MySQL 数据库时,关于如何追踪我遇到的错误,您能给我什么建议?

错误信息是:

MySql.Data.MySqlClient.MySqlException: Duplicate entry '26012' for key 'StockNumber_Number_UNIQUE'

查看日志证明26012的StockNumber_Number还没有插入。

正在使用的产品。

  • Visual Studio 2008。
  • mysql.data.dll 6.0.4.0.
  • Windows 7 Ultimate 64 位和 Windows 2003 32 位。
  • 定制的 ORM 框架(有源代码)。
  • 从 Access 2003 数据库导入数据。

该代码适用于 3000 - 5000 次导入。

在完整运行中导致问题的正在导入的记录如果仅单独导入则可以正常工作。如果我以不同的方式对要导入的数据进行排序,我也会在其他记录上看到错误。

已尝试使用和不使用交易进行导入。

已经退出系统。

创建表的SQL命令:

CREATE TABLE `RareItems_RareItems` (
`RareItemKey` CHAR(36) NOT NULL PRIMARY KEY,
`StockNumber_Text` VARCHAR(7) NOT NULL,
`StockNumber_Number` INT NOT NULL AUTO_INCREMENT,
UNIQUE INDEX `StockNumber_Number_UNIQUE` (`StockNumber_Number` ASC),
`OurPercentage` NUMERIC ,
`SellPrice` NUMERIC(19, 2) ,
`Author` VARCHAR(250) ,
`CatchWord` VARCHAR(250) ,
`Title` TEXT ,
`Publisher` VARCHAR(250) ,
`InternalNote` VARCHAR(250) ,
`DateOfPublishing` VARCHAR(250) ,
`ExternalNote` LONGTEXT ,
`Description` LONGTEXT ,
`Scrap` LONGTEXT ,
`SuppressionKey` CHAR(36) NOT NULL,
`TypeKey` CHAR(36) NOT NULL,
`CatalogueStatusKey` CHAR(36) NOT NULL,
`CatalogueRevisedDate` DATETIME ,
`CatalogueRevisedByKey` CHAR(36) NOT NULL,
`CatalogueToBeRevisedByKey` CHAR(36) NOT NULL,
`DontInsure` BIT NOT NULL,
`ExtraCosts` NUMERIC(19, 2) ,
`IsWebReady` BIT NOT NULL,
`LocationKey` CHAR(36) NOT NULL,
`LanguageKey` CHAR(36) NOT NULL,
`CatalogueDescription` VARCHAR(250) ,
`PlacePublished` VARCHAR(250) ,
`ToDo` LONGTEXT ,
`Headline` VARCHAR(250) ,
`DepartmentKey` CHAR(36) NOT NULL,
`Temp1` INT ,
`Temp2` INT ,
`Temp3` VARCHAR(250) ,
`Temp4` VARCHAR(250) ,
`InternetStatusKey` CHAR(36) NOT NULL,
`InternetStatusInfo` LONGTEXT ,
`PurchaseKey` CHAR(36) NOT NULL,
`ConsignmentKey` CHAR(36) ,
`IsSold` BIT NOT NULL,
`RowCreated` DATETIME NOT NULL,
`RowModified` DATETIME NOT NULL
);

插入记录的SQL命令及参数:

INSERT INTO `RareItems_RareItems` 
(`RareItemKey`, `StockNumber_Text`, `StockNumber_Number`, `OurPercentage`, `SellPrice`, `Author`, `CatchWord`, `Title`, `Publisher`, `InternalNote`, `DateOfPublishing`, `ExternalNote`, `Description`, `Scrap`, `SuppressionKey`, `TypeKey`, `CatalogueStatusKey`, `CatalogueRevisedDate`, `CatalogueRevisedByKey`, `CatalogueToBeRevisedByKey`, `DontInsure`, `ExtraCosts`, `IsWebReady`, `LocationKey`, `LanguageKey`, `CatalogueDescription`, `PlacePublished`, `ToDo`, `Headline`, `DepartmentKey`, `Temp1`, `Temp2`, `Temp3`, `Temp4`, `InternetStatusKey`, `InternetStatusInfo`, `PurchaseKey`, `ConsignmentKey`, `IsSold`, `RowCreated`, `RowModified`)
VALUES
(@RareItemKey, @StockNumber_Text, @StockNumber_Number, @OurPercentage, @SellPrice, @Author, @CatchWord, @Title, @Publisher, @InternalNote, @DateOfPublishing, @ExternalNote, @Description, @Scrap, @SuppressionKey, @TypeKey, @CatalogueStatusKey, @CatalogueRevisedDate, @CatalogueRevisedByKey, @CatalogueToBeRevisedByKey, @DontInsure, @ExtraCosts, @IsWebReady, @LocationKey, @LanguageKey, @CatalogueDescription, @PlacePublished, @ToDo, @Headline, @DepartmentKey, @Temp1, @Temp2, @Temp3, @Temp4, @InternetStatusKey, @InternetStatusInfo, @PurchaseKey, @ConsignmentKey, @IsSold, @RowCreated, @RowModified)

@RareItemKey = 0b625bd6-776d-43d6-9405-e97159d172a6
@StockNumber_Text = 199305
@StockNumber_Number = 26012
@OurPercentage = 22.5
@SellPrice = 1250
@Author = SPARRMAN, Anders.
@CatchWord = COOK: SECOND VOYAGE
@Title = A Voyage Round the World with Captain James Cook in H.M.S. Resolution… Introduction and notes by Owen Rutter, wood engravings by Peter Barker-Mill.
@Publisher =
@InternalNote =
@DateOfPublishing = 1944
@ExternalNote = The first English translation of Sparrman’s narrative, which had originally been published in Sweden in 1802-1818, and the only complete version of his account to appear in English. The eighteenth-century translation had appeared some time before the Swedish publication of the final sections of his account. Sparrman’s observant and well-written narrative of the second voyage contains much that appears nowhere else, emphasising naturally his interests in medicine, health, and natural history.<br><br>One of 350 numbered copies: a handsomely produced and beautifully illustrated work.
@Description = Small folio, wood-engravings in the text; original olive glazed cloth, top edges gilt, a very good copy. London, Golden Cockerel Press, 1944.
@Scrap =
@SuppressionKey = 00000000-0000-0000-0000-000000000000
@TypeKey = 93f58155-7471-46ad-84c5-262ab9dd37e8
@CatalogueStatusKey = 00000000-0000-0000-0000-000000000003
@CatalogueRevisedDate =
@CatalogueRevisedByKey = c4f6fc06-956d-44c4-b393-0d5462cbffec
@CatalogueToBeRevisedByKey = 00000000-0000-0000-0000-000000000000
@DontInsure = False
@ExtraCosts =
@IsWebReady = False
@LocationKey = 00000000-0000-0000-0000-000000000000
@LanguageKey = 00000000-0000-0000-0000-000000000000
@CatalogueDescription =
@PlacePublished = Golden Cockerel Press
@ToDo =
@Headline =
@DepartmentKey = 529578a3-9189-40de-b656-eef9039d00b8
@Temp1 =
@Temp2 =
@Temp3 =
@Temp4 = v
@InternetStatusKey = 00000000-0000-0000-0000-000000000000
@InternetStatusInfo =
@PurchaseKey = 00000000-0000-0000-0000-000000000000
@ConsignmentKey =
@IsSold = True
@RowCreated = 8/04/2010 8:49:16 PM
@RowModified = 8/04/2010 8:49:16 PM

关于导致错误的原因和/或如何追踪导致问题的建议?

最佳答案

抱歉,我是 MSSQL 开发人员,所以这里可能不合时宜,但为什么要插入 StockNumber_Number 作为插入的一部分。它是一个 auto_increment 字段,因此肯定会为您创建。

要么从您的插入中删除该字段,要么不要将其设为 auto_increment,问题就会消失。

关于.net - 需要帮助来调试使用 .Net 和 MySQL 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2599392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com