代码如下
using (OracleConnection con = new OracleConnection("connectionstring"))
{
con.Open();
using (TransactionScope scope = new TransactionScope())
{
OracleCommand cmd = new OracleCommand("Insert Into Producer(ProducerId,Name,NickName,Telephone,Nationality) Values(:ProducerId,:Name,:NickName,:Telephone,:Nationality)", con);
cmd.Parameters.Add(new OracleParameter("ProducerId", Guid.NewGuid()));
cmd.Parameters.Add(new OracleParameter("Name", "Test for Insert"));
cmd.Parameters.Add(new OracleParameter("NickName", "Test"));
cmd.Parameters.Add(new OracleParameter("Telephone", "111111"));
cmd.Parameters.Add(new OracleParameter("Nationality", "China"));
cmd.ExecuteNonQuery();
scope.Complete();
}
con.Close();
}
报的是Unable to enlist in a distributed transaction这个错误。
环境:
Windows 7, VS2010,Oracle 10g,已启动distributed transaction coordinator与Com+ System Application等服务,已安装相应版本的ODAC,允许MSDTC的Network Access。