EDN Admin
Well-known member
I dont know why, after execute a command the throw an exception, but it doesnt rollback, i need your help, im using EntLib 5.0. Thanks
<pre style="font-family:Consolas; font-size:13px; color:black; background:none repeat scroll 0% 0% white <span style="color:blue using (<span style="color:#2b91af DbConnection conn = DB.CreateConnection())
{
conn.Open();
<span style="color:blue using (<span style="color:#2b91af DbTransaction trans = conn.BeginTransaction())
{
<span style="color:blue try
{
<span style="color:#2b91af Address address = <span style="color:blue new <span style="color:#2b91af Address();
<span style="color:#2b91af CompanyAddresses com_addr = <span style="color:blue new <span style="color:#2b91af CompanyAddresses();
ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "PRIMARYADDRKEY"] = 1;
ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "CNTCTKEY"] = 1;
<span style="color:green //Insert company info
<span style="color:blue string sql = <span style="color:#2b91af String.Format(<span style="color:#a31515 "pkg_sm.Sp_tsmcompany_insert");
<span style="color:#2b91af DbCommand cmd = DB.GetStoredProcCommand((sql));
<span style="color:#2b91af OracleParameter param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_companyid", <span style="color:#2b91af OracleType.VarChar);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "COMPANYID"];
cmd.Parameters.Add(param);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_companyname", <span style="color:#2b91af OracleType.VarChar);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "COMPANYNAME"];
cmd.Parameters.Add(param);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_primaryAddrkey", <span style="color:#2b91af OracleType.Number);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "PRIMARYADDRKEY"];
cmd.Parameters.Add(param);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_cntctkey", <span style="color:#2b91af OracleType.VarChar);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "CNTCTKEY"];
cmd.Parameters.Add(param);
<span style="color:#2b91af OracleParameter companykey = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_companykey", <span style="color:#2b91af OracleType.Number);
companykey.Direction = <span style="color:#2b91af ParameterDirection.Output;
cmd.Parameters.Add(companykey);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_currkey", <span style="color:#2b91af OracleType.Number);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "CURRKEY"];
cmd.Parameters.Add(param);
DB.ExecuteNonQuery(cmd, trans);
<span style="color:blue throw <span style="color:blue new <span style="color:#2b91af Exception(<span style="color:#a31515 "Test");
trans.Commit();
}
<span style="color:blue catch (<span style="color:#2b91af Exception ex)
{
trans.Rollback();
<span style="color:blue throw ex;
}
<span style="color:blue finally
{
conn.Close();
}
}
}<br/><br/>Oracle config:<br/><br/><span style="color:blue <<span style="color:#a31515 section<span style="color:blue <span style="color:red name<span style="color:blue ="<span style="color:blue oracleConnectionSettings"<span style="color:blue <span style="color:red type<span style="color:blue ="<span style="color:blue Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings,Microsoft.Practices.EnterpriseLibrary.Data"<span style="color:blue />
<br/><span style="color:blue <<span style="color:#a31515 connectionStrings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add<span style="color:blue <span style="color:red name<span style="color:blue ="<span style="color:blue myDatabase"<span style="color:blue <span style="color:red connectionString<span style="color:blue ="<span style="color:blue Data Source=10.0.1.17/erp;Persist Security Info=True;User ID=i3erp;Password=erperp;"
<span style="color:blue <span style="color:red providerName<span style="color:blue ="<span style="color:blue System.Data.OracleClient"<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 connectionStrings<span style="color:blue ><br/>[/code]
View the full article
<pre style="font-family:Consolas; font-size:13px; color:black; background:none repeat scroll 0% 0% white <span style="color:blue using (<span style="color:#2b91af DbConnection conn = DB.CreateConnection())
{
conn.Open();
<span style="color:blue using (<span style="color:#2b91af DbTransaction trans = conn.BeginTransaction())
{
<span style="color:blue try
{
<span style="color:#2b91af Address address = <span style="color:blue new <span style="color:#2b91af Address();
<span style="color:#2b91af CompanyAddresses com_addr = <span style="color:blue new <span style="color:#2b91af CompanyAddresses();
ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "PRIMARYADDRKEY"] = 1;
ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "CNTCTKEY"] = 1;
<span style="color:green //Insert company info
<span style="color:blue string sql = <span style="color:#2b91af String.Format(<span style="color:#a31515 "pkg_sm.Sp_tsmcompany_insert");
<span style="color:#2b91af DbCommand cmd = DB.GetStoredProcCommand((sql));
<span style="color:#2b91af OracleParameter param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_companyid", <span style="color:#2b91af OracleType.VarChar);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "COMPANYID"];
cmd.Parameters.Add(param);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_companyname", <span style="color:#2b91af OracleType.VarChar);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "COMPANYNAME"];
cmd.Parameters.Add(param);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_primaryAddrkey", <span style="color:#2b91af OracleType.Number);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "PRIMARYADDRKEY"];
cmd.Parameters.Add(param);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_cntctkey", <span style="color:#2b91af OracleType.VarChar);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "CNTCTKEY"];
cmd.Parameters.Add(param);
<span style="color:#2b91af OracleParameter companykey = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_companykey", <span style="color:#2b91af OracleType.Number);
companykey.Direction = <span style="color:#2b91af ParameterDirection.Output;
cmd.Parameters.Add(companykey);
param = <span style="color:blue new <span style="color:#2b91af OracleParameter(<span style="color:#a31515 "p_currkey", <span style="color:#2b91af OracleType.Number);
param.Direction = <span style="color:#2b91af ParameterDirection.Input;
param.Value = ds.Tables[<span style="color:#a31515 "TSMCOMPANY"].Rows[0][<span style="color:#a31515 "CURRKEY"];
cmd.Parameters.Add(param);
DB.ExecuteNonQuery(cmd, trans);
<span style="color:blue throw <span style="color:blue new <span style="color:#2b91af Exception(<span style="color:#a31515 "Test");
trans.Commit();
}
<span style="color:blue catch (<span style="color:#2b91af Exception ex)
{
trans.Rollback();
<span style="color:blue throw ex;
}
<span style="color:blue finally
{
conn.Close();
}
}
}<br/><br/>Oracle config:<br/><br/><span style="color:blue <<span style="color:#a31515 section<span style="color:blue <span style="color:red name<span style="color:blue ="<span style="color:blue oracleConnectionSettings"<span style="color:blue <span style="color:red type<span style="color:blue ="<span style="color:blue Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings,Microsoft.Practices.EnterpriseLibrary.Data"<span style="color:blue />
<br/><span style="color:blue <<span style="color:#a31515 connectionStrings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add<span style="color:blue <span style="color:red name<span style="color:blue ="<span style="color:blue myDatabase"<span style="color:blue <span style="color:red connectionString<span style="color:blue ="<span style="color:blue Data Source=10.0.1.17/erp;Persist Security Info=True;User ID=i3erp;Password=erperp;"
<span style="color:blue <span style="color:red providerName<span style="color:blue ="<span style="color:blue System.Data.OracleClient"<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 connectionStrings<span style="color:blue ><br/>[/code]
View the full article