本文整理汇总了C#中Westwind.Utilities.Data.SqlDataAccess.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataAccess.BeginTransaction方法的具体用法?C# SqlDataAccess.BeginTransaction怎么用?C# SqlDataAccess.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Westwind.Utilities.Data.SqlDataAccess
的用法示例。
在下文中一共展示了SqlDataAccess.BeginTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RestoreBackupTable
/// <summary>
/// Restores the localization table from a backup table by first wiping out
/// </summary>
/// <param name="backupTableName"></param>
/// <returns></returns>
public bool RestoreBackupTable(string backupTableName)
{
if (backupTableName == null)
backupTableName = DbResourceConfiguration.Current.ResourceTableName + "_Backup";
using (var data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString))
{
data.BeginTransaction();
if (data.ExecuteNonQuery("delete from " + DbResourceConfiguration.Current.ResourceTableName) < 0)
{
data.RollbackTransaction();
ErrorMessage = data.ErrorMessage;
return false;
}
string sql =
@"insert into {0}
(ResourceId,Value,LocaleId,ResourceSet,Type,BinFile,TextFile,FileName,Comment)
select ResourceId,Value,LocaleId,ResourceSet,Type,BinFile,TextFile,FileName,Comment from {1}";
sql = string.Format(sql, DbResourceConfiguration.Current.ResourceTableName, backupTableName);
if (data.ExecuteNonQuery(sql) < 0)
{
data.RollbackTransaction();
ErrorMessage = data.ErrorMessage;
return false;
}
data.CommitTransaction();
}
return true;
}
示例2: GenerateResources
/// <summary>
/// Persists resources to the database - first wipes out all resources, then writes them back in
/// from the ResourceSet
/// </summary>
/// <param name="ResourceList"></param>
/// <param name="CultureName"></param>
/// <param name="BaseName"></param>
public bool GenerateResources(IDictionary ResourceList, string CultureName, string BaseName, bool DeleteAllResourceFirst)
{
if (ResourceList == null)
throw new InvalidOperationException("No Resources");
if (CultureName == null)
CultureName = string.Empty;
using (SqlDataAccess Data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString))
{
if (!Data.BeginTransaction())
return false;
// Set transaction to be shared by other methods
Transaction = Data.Transaction;
try
{
// First delete all resources for this resource set
if (DeleteAllResourceFirst)
{
int Result = Data.ExecuteNonQuery("delete " + DbResourceConfiguration.Current.ResourceTableName + " where [email protected] and [email protected]",
Data.CreateParameter("@LocaleId", CultureName),
Data.CreateParameter("@ResourceSet", BaseName));
if (Result == -1)
{
Data.RollbackTransaction();
return false;
}
}
// Now add them all back in one by one
foreach (DictionaryEntry Entry in ResourceList)
{
if (Entry.Value != null)
{
int Result = 0;
if (DeleteAllResourceFirst)
Result = AddResource(Entry.Key.ToString(), Entry.Value, CultureName, BaseName, null);
else
Result = UpdateOrAdd(Entry.Key.ToString(), Entry.Value, CultureName, BaseName, null);
if (Result == -1)
{
Data.RollbackTransaction();
return false;
}
}
}
}
catch
{
Data.RollbackTransaction();
return false;
}
Data.CommitTransaction();
}
// Clear out the resources
ResourceList = null;
return true;
}