[英]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.