1.机器启动 OracleMTSRecoveryService
2.确保 MSDTC 服务正确配置
3.如果没有分布式事务,连接字符串添加 PROMOTABLE TRANSACTION=LOCAL
但是我发现,上述方式依然不能解决我的问题.
我的数据库连接字符串格和他的是一样的:
Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1522)))(CONNECT_DATA =(SERVICE_NAME = ora10)));User Id=ipms;Password=ipms;
我在本地建立了服务名后, 把数据库连接字符串改为:
Data Source=ipms;User Id=ipms;Password=ipms;
分布式事务就好了.
老外原文:(鬼知道什么时候没了链接)
Using TransactionScope with ODP.NET
If you are using Oracle Database Provider for .NET (ODP.NET) and you want to use TransactionScope'd transactions, you may have gotten the dreaded "Data provider internal error(-3000) [System.String]" exception. I'll explain how I fixed it.
First, if you want to support distributed transactions, make sure you have the OracleMTSRecoveryService service installed and running on your machine (it comes with the Oracle Data Access Components installation), or any other machine on your network, as long as properly configured on the MSDTC tab on the Component Services applet.
If you don't need distributed transactions, you can place the connection string setting PROMOTABLE TRANSACTION=LOCAL on your connection string, for example:
DATA SOURCE=(DESCRIPTION=(ADDRESS=(COMMUNITY=TCP.Some.Community)(PROTOCOL=TCP)(HOST=Some.Host)(PORT=1522))(CONNECT_DATA=(SID=SomeSid)));USER ID=SomeUsername;PASSWORD=SomePassword;PROMOTABLE TRANSACTION=LOCAL
Now you can have:
using (TransactionScope tx = new TransactionScope()){
using (OracleConnection con = new OracleConnection(@"DATA SOURCE=(DESCRIPTION=(ADDRESS=(COMMUNITY=TCP.Some.Community)(PROTOCOL=TCP)(HOST=Some.Host)(PORT=1522))(CONNECT_DATA=(SID=SomeSid)));USER ID=SomeUsername;PASSWORD=SomePassword;PROMOTABLE TRANSACTION=LOCAL"))
using (OracleCommand cmd = con.CreateCommand()){
con.Open(); //no longer crashes here
cmd.CommandText = "SELECT sysdate FROM dual"; DateTime date = (DateTime)cmd.ExecuteScalar();}
}
If you need more information, check the Oracle Data Provider for .NET Developer's Guide, it's the e10927.pdf file on the B28359_01\win.111 folder of the Oracle documentation (version 11g).