简体   繁体   English

从 SQL 服务器存储过程插入 DB2 数据库成功,但使用实体框架包装相同的过程失败

[英]Inserting into DB2 database from SQL Server stored procedure succeeds, but wrapping the same procedure using Entity Framework fails

I need to be able to insert rows into a set of tables in a DB2 database from a Microsoft SQL Server database.我需要能够从 Microsoft SQL 服务器数据库将行插入到 DB2 数据库中的一组表中。 I created stored procedures that can insert rows into the DB2 database using a linked server, referencing the target tables by their 4 part names.我创建了存储过程,可以使用链接服务器将行插入到 DB2 数据库中,并通过 4 个部分名称引用目标表。 These procedures work and I am able to insert records by calling them in SQL Server Management Studio.这些过程有效,我可以通过在 SQL Server Management Studio 中调用它们来插入记录。

The schemas are different between the two databases, so I am using a C# program and Entity Framework wrap these stored procedures to help me perform the mapping.两个数据库之间的模式不同,所以我使用 C# 程序和实体框架包装这些存储过程来帮助我执行映射。 When running my program an exception is thrown with the message运行我的程序时,会抛出异常并显示消息

The operation could not be performed because OLE DB provider "IBMDASQL" for linked server "LinkedServer" was unable to begin a distributed transaction无法执行操作,因为链接服务器“LinkedServer”的 OLE DB 提供程序“IBMDASQL”无法开始分布式事务

Running a SQL trace and replaying the commands created by Entity Framework in SQL Server Management Studio creates the desired records in DB2.运行 SQL 跟踪并重放由 SQL Server Management Studio 中的实体框架创建的命令在 DB2 中创建所需的记录。

What am I missing here to get these stored procedure calls working from Entity Framework?为了让这些存储过程调用从实体框架工作,我在这里缺少什么?

My problem was solved by setting a configuration property in my database context.通过在我的数据库上下文中设置配置属性解决了我的问题。

db.Configuration.EnsureTransactionsForFunctionsAndCommands = false; db.Configuration.EnsureTransactionsForFunctionsAndCommands = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用存储过程从数据库重新加载Entity Framework 5 - Entity Framework 5 reload from database using a stored procedure 使用存储过程将数据插入SQL Server - Inserting data into SQL Server by using a stored procedure 在实体框架中使用存储过程 - using stored procedure in entity framework 使用存储过程使用文本框中的值更新SQL Server数据库 - Updating SQL Server database with values from textboxes using stored procedure 带有 SQL 服务器存储过程的 Entity Framework.Net 6 – 未提供参数 - Entity Framework .Net 6 with SQL Server stored procedure – parameter not supplied 使用实体框架调用存储过程总是返回相同的值 - Using Entity framework calling stored procedure return same value always 使用SQL Server数据库和ASP.NET应用程序中的存储过程在多个表中插入记录 - Inserting records in multiple tables using stored procedure in SQL Server database and ASP.NET application 从实体框架生成的数据库上下文中调用存储过程 - Calling Stored Procedure from Database Context generated by Entity Framework 如何首先从实体框架+数据库中的存储过程中获取结果 - how to get the result from stored procedure in entity framework + database first 从MVC使用SQL Server存储过程 - Using SQL Server stored procedure from MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM