zzzprojects / Dapper-Plus

Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
https://dapper-plus.net/
384 stars 85 forks source link

BulkInsert Postgres => An error occured while retrieving the InformationSchemaTable information. See the inner exception for details. #137

Closed kbMetrel closed 9 months ago

kbMetrel commented 9 months ago

Description

Trying to use BulkInsert on Postgres 16.1. Using settings var context = new DapperPlusContext(conn, tran); context.Entity<DbSerial>().Table("SerialsToWebCdId").Identity(x => x.Id, true); Or const string MappingKey = "ForDocumentDetailsBulkInsert"; DapperPlusManager.Entity<DbSerial>(MappingKey).Table("SerialsToWebCdId").Identity(x => x.Id); Or DapperPlusManager.Entity<DbSerial>().Table("SerialsToWebCdId").Identity(x => x.Id, true); When Executing conn.BulkInsert getting an error: An error occured while retrieving the InformationSchemaTable information

Exception

If you are seeing an exception, include the full exceptions details (message and stack trace).


Exception message:
An error occured while retrieving the InformationSchemaTable information. See the inner exception for details.
InnerExceptionMessage:
25P02: current transaction is aborted, commands ignored until end of transaction block
Stack trace:
   at Z.BulkOperations.BulkOperation.()
   at Z.BulkOperations.BulkOperation.Execute()
   at Z.BulkOperations.BulkOperation.BulkInsert()
   at Z.Dapper.Plus.DapperPlusAction.Execute()
   at Z.Dapper.Plus.DapperPlusAction..ctor(BaseDapperPlusActionSet action, String key, DapperPlusActionKind kind, Object dataSource)
   at Z.Dapper.Plus.DapperPlusActionSet`1.AddAction(String mapperKey, DapperPlusActionKind actionKind, IEnumerable`1 item)
   at Z.Dapper.Plus.DapperPlusActionSet`1.DapperPlusActionSetBuilder(DapperPlusContext context, IDbConnection connection, IDbTransaction transaction, String mapperKey, DapperPlusActionKind actionKind, IEnumerable`1 items, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusActionSet`1..ctor(DapperPlusContext context, IDbConnection connection, String mapperKey, DapperPlusActionKind actionKind, IEnumerable`1 items, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, String mapperKey, IEnumerable`1 items, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, IEnumerable`1 items, Func`2[] selectors)
   at WebCd.Common.SqlFactories.PostgresSerialsRepository.CreateSerialsOnDb(List`1 serials) in E:\PROJECTS\WebCdAll\WebCd\WebCd.Common\WebCd.Common.SqlFactories\PostgresSerialsRepository.cs:line 82
JonathanMagnan commented 9 months ago

Hello @kbMetrel ,

Do you think you could create a runnable project with the issue? It doesn’t need to be your project, just a new solution with the minimum code to reproduce the issue.

We tried on our side but we are not able to reproduce it.

What we especially want to know is more how you use the BulkInsert and the Transaction. So, we believe the project will give us some additional hints that we are missing that could explain the current error.

Best Regards,

Jon

kbMetrel commented 9 months ago

Hi Jon!

Sure. Attaching the project.... I added CreateDb.txt for how the Postgres Table is created...

Hope that helps! DemoApp.zip

JonathanMagnan commented 9 months ago

Hello @kbMetrel ,

Thank you for the project.

Cause

The error happen because the table name is not escaped in the CreateDB.txt script. So when the following command is executed CREATE TABLE IF NOT EXISTS SerialsToWebCdId, the table name created is all in lowercase: serialstowebcdid

And in your mapping, you specify the same table name DapperPlusManager.Entity<DbSerial>().Table("SerialsToWebCdId"), but on our side, we escape it.

Solution

So to fix it, you can either:

On our side, we indeed have an error by not showing the right message error when this situation happen within a transaction. We will fix it on our side, so the next time it will be easiest to know that the table name doesn't match.

Let me know if that explain correctly the cause and how to solve this issue.

Best Regards,

Jon

kbMetrel commented 9 months ago

Heh, yeah!

@JonathanMagnan, thanks for the feedback! It works like a charm! :)

Will be buying the license! :)

Best regards,

Karl