本文整理汇总了C#中ICustomer.getSQLContextInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ICustomer.getSQLContextInfo方法的具体用法?C# ICustomer.getSQLContextInfo怎么用?C# ICustomer.getSQLContextInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICustomer
的用法示例。
在下文中一共展示了ICustomer.getSQLContextInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: register
/// <summary>
/// Registers/adds new user to database.
/// </summary>
/// <param name="userID">User id for account creation/login purposes as specified by user.</param>
/// <param name="password">Password as specified by user.</param>
/// <param name="fullname">Name as specified by user.</param>
/// <param name="address">Address as specified by user.</param>
/// <param name="email">Email as specified by user.</param>
/// <param name="creditcard">Credit card number as specified by user.</param>
/// <param name="openBalance">Open balance as specified by user. </param>
public AccountDataModel register(string userID, string password, string fullname, string address, string email, string creditcard, decimal openBalance)
{
//Switch is two let you configure which transaction model you want to benchmark/test.
switch (Settings.TRANSACTION_MODEL)
{
case (StockTraderUtility.TRANSACTION_MODEL_SYSTEMDOTTRANSACTION_TRANSACTION):
{
//This short try/catch block is introduced to deal with idle-timeout on SQL Azure
//connections. It may not be required in the near future, but as of publication
//SQL Azure disconnects idle connections after 30 minutes. While command retry-logic
//in the DAL automatically deals with this, when performing a tx, with the BSL handling
//tx boundaries, we want to go into the tx with known good connections. The try/catch below
//ensures this.
try
{
dalCustomer = Trade.DALFactory.Customer.Create(Settings.DAL);
dalCustomer.Open(Settings.TRADEDB_SQL_CONN_STRING);
dalCustomer.getSQLContextInfo();
}
catch { }
finally { dalCustomer.Close(); }
System.Transactions.TransactionOptions txOps = new TransactionOptions();
txOps.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
txOps.Timeout = TimeSpan.FromSeconds((double)Settings.SYSTEMDOTTRANSACTION_TIMEOUT);
//Start our System.Transactions tx with the options set above. System.Transactions
//will handle rollbacks automatically if there is an exception; note the
//difference between the System.Transaction case and the ADO.NET transaction case;
//and where the dal.Open() happens (which opens a 'hidden' DB connection in DAL).
//System.Transactions will automatically enlist ANY connection
//opened within the tx scope in the transaction for you. Since it supports distributed
//tx's; it frees you quite a bit, with the caveat of the overhead of doing a distributed
//tx when you do not need one. Hence: lightweight System.Transactions with an auto-promote to DTC
//only if needed, meaning two or more operations use database connections spanning physicall different databases.
//ADO.NET txs always require an already-open connection before starting a tx, and txs cannot span multiple databases, just tables.
using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required, txOps))
{
//Now open the connection, after entering tx scope.
dalCustomer.Open(Settings.TRADEDB_SQL_CONN_STRING);;
try
{
AccountDataModel newCustomer = addNewRegisteredUser(userID, password, fullname, address, email, creditcard, openBalance);
//Scope complete, commit work.
tx.Complete();
return newCustomer;
}
catch
{
//no rollback needed, infrastructure will never commit without
//scope.Complete() and immediately issue rollback on and unhandled
//exception.
throw;
}
finally
{
dalCustomer.Close();
}
}
}
case (StockTraderUtility.TRANSACTION_MODEL_ADONET_TRANSACTION):
{
//ADO.NET TX case: First you need to open the connecton.
dalCustomer.Open(Settings.TRADEDB_SQL_CONN_STRING);;
//Now you start TX
dalCustomer.BeginADOTransaction();
try
{
AccountDataModel newCustomer = addNewRegisteredUser(userID, password, fullname, address, email, creditcard, openBalance);
//done, commit.
dalCustomer.CommitADOTransaction();
return newCustomer;
}
catch
{
//explicit rollback needed.
dalCustomer.RollBackTransaction();
throw;
}
finally
{
//ALWAYS call dal.Close is using StockTrader DAL implementation;
//this is equivalent to calling Connection.Close() in the DAL --
//but for a generic DB backend as far as the BSL is concerned.
dalCustomer.Close();
}
}
}
//.........这里部分代码省略.........