本文整理汇总了C#中SqlDatabase.RollbackTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDatabase.RollbackTransaction方法的具体用法?C# SqlDatabase.RollbackTransaction怎么用?C# SqlDatabase.RollbackTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlDatabase
的用法示例。
在下文中一共展示了SqlDatabase.RollbackTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateProcessConfigXml
public static void UpdateProcessConfigXml(PTR3Core core, String converterName, String processConfigurationXml)
{
String ptrServer = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "data-base:address");
String ptrDatabase = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "data-base:name");
String ptrUser = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "data-base:user");
String ptrPassword = PasswordEncoder.PtrDecryptText(ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "data-base:password"));
// Zapis xml do bazy danych.
PTR3Core.LOG.Log(MsgStatusEnum.MS_Deb1, "Create connection with PTR DB");
SqlDatabase ptrDb = new SqlDatabase(ptrServer, ptrDatabase, ptrUser, ptrPassword);
if(ptrDb == null)
{
throw new Exception("Connection with PTR database failed");
}
SqlDatabase ptrConfModDb = new SqlDatabase(ptrServer, ptrDatabase, ptrUser, ptrPassword);
if(ptrConfModDb == null)
{
throw new Exception("Connection with PTR database failed");
}
try
{
PTR3Core.LOG.Log(MsgStatusEnum.MS_Deb1, "Lock " + converterName + " Resources");
string machineName = "";
string processDescr = "";
string lockResource = String.Format("{0}:{1}:{2}", ptrServer, ptrDatabase, converterName);
DateTime lockTime = DateTime.MinValue;
if(!core.LockResource(ptrDb, lockResource, 60, out machineName, out processDescr, out lockTime))
{
throw new Exception(String.Format("Resource: {0} was blocked by another process [Machine name: {1}, Process descr: {2}, at: {3}]",
lockResource, machineName, processDescr, lockTime));
}
ptrConfModDb.BeginTransaction();
core.UpdateProcessConfiguration(ptrConfModDb, processConfigurationXml);
ptrConfModDb.CommitTransaction();
}
catch(Exception ex)
{
if(ptrDb != null)
{
ptrDb.RollbackTransaction();
}
if(ptrConfModDb != null)
{
ptrConfModDb.RollbackTransaction();
}
throw ex;
}
finally
{
if(ptrDb != null)
{
ptrDb.Close();
ptrDb = null;
}
if(ptrConfModDb != null)
{
ptrConfModDb.Close();
ptrConfModDb = null;
}
}
}