问题
I try to execute the follwing statement from a c# program with ODP.NET:
string sql = "BEGIN dbms_session.set_nls('NLS_NUMERIC_CHARACTERS','''.,'''); END;";
using (OracleConnection connection = new OracleConnection("Data Source=db;User Id=a;Password=b"))
{
connection.Open();
using (OracleCommand command = new OracleCommand(sql, connection))
{
command.ExecuteNonQuery();
}
connection.Close();
}
I retrieve the follwing error message:
ORA-02074: cannot SET NLS in a distributed transaction
I don't use any transaction in my code. Is the OracleConnection an implicit distributed transaction? If I add enlist=false to the connection string it works. But I don't know why.
回答1:
I don't know much about C#, but are you sure you need the connection.Open() and connection.Close() statements? I would assume that the using statement takes care of that.
回答2:
I don't need distributed transactions in my environment, so I just solved this by appending enlist=false
to my connection string. Hope it may be useful to someone.
来源:https://stackoverflow.com/questions/11221971/set-nls-fails-over-oracle-odp-net