本文整理汇总了C#中DBConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnection.Open方法的具体用法?C# DBConnection.Open怎么用?C# DBConnection.Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection.Open方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveTraceToDb
public override void SaveTraceToDb()
{
LoggingService.Info("开始保存痕迹记录...");
DBConnection connection = new DBConnection(base.SMDataSource);
connection.Open();
try
{
if (LoggingService.IsDebugEnabled)
{
LoggingService.DebugFormatted("共有修改或添加的痕迹记录:{0}条,删除记录:{1}条", new object[] { this.TraceTable.Rows.Count, (this._RecDelTable == null) ? 0 : this._RecDelTable.Rows.Count });
}
DbTransaction transaction = connection.BeginTrasaction() as DbTransaction;
DbDataAdapter adapter = this.TraceTable.ExtendedProperties["da"] as DbDataAdapter;
adapter.InsertCommand.Connection = connection.Connection as DbConnection;
adapter.InsertCommand.Transaction = transaction;
adapter.Update(this.TraceTable);
if (TraceUtil.CanTraceLevel(TraceLevel.Deleted))
{
DbDataAdapter adapter2 = this._RecDelTable.ExtendedProperties["da"] as DbDataAdapter;
adapter2.InsertCommand.Connection = connection.Connection as DbConnection;
adapter2.InsertCommand.Transaction = transaction;
adapter2.Update(this._RecDelTable);
}
connection.CommitTransaction();
}
catch (DbException exception)
{
connection.RollBackTransaction();
string dataSetName = "TraceDb" + DateTimeHelper.GetNow().ToString();
DataSet set = new DataSet(dataSetName);
set.Tables.Add(this.TraceTable);
set.Tables.Add(this._RecDelTable);
set.WriteXml(Environment.CurrentDirectory + @"\" + dataSetName + ".xml");
throw new DataFormException("数据修改日志记录保存不成功能(数据已成功能保存)!", exception);
}
finally
{
connection.Close();
this.TraceTable.Rows.Clear();
if (this._RecDelTable != null)
{
this._RecDelTable.Rows.Clear();
}
}
}
示例2: RefreshDataset
public DataSet RefreshDataset(SMDataSource smDS, DataSet ds)
{
DBConnection connection = new DBConnection(smDS);
connection.Open();
try
{
for (int i = 0; i < ds.Tables.Count; i++)
{
DataTable dt = ds.Tables[i];
dt.Rows.Clear();
string sql = (string) dt.ExtendedProperties["selectsql"];
connection.ExecuteSql(dt, sql);
}
}
finally
{
connection.Close();
}
return ds;
}
示例3: GetDs
public virtual DataSet GetDs(string dataFormID, string keyValue)
{
DataSet set2;
DAODataForm dAODataForm = this.GetDAODataForm(dataFormID);
if (LoggingService.IsInfoEnabled)
{
LoggingService.InfoFormatted("准备获取表单:'{0}',键值:'{1}'的业务表单数据!", new object[] { dAODataForm.Name, keyValue });
}
if (dAODataForm == null)
{
throw new DataFormException("没有找到数据表单配置信息!");
}
DataSet set = new DataSet(dAODataForm.Name);
DBConnection dbcn = new DBConnection(dAODataForm.DataSource);
dbcn.Open();
try
{
this.SyncDataSouce(keyValue, dAODataForm, dbcn);
foreach (DAODataTable table in dAODataForm.BindTables)
{
if (!set.Tables.Contains(table.Name))
{
set.Tables.Add(this.GetDataTable(table, keyValue, dbcn));
}
}
set.AcceptChanges();
set2 = set;
}
catch (ApplicationException exception)
{
throw exception;
}
finally
{
dbcn.Close();
}
return set2;
}
示例4: Delete
public static void Delete(IDictionary<DAODataSet, string> deletes)
{
Exception exception;
try
{
string str = string.Empty;
DAODataSet key = null;
List<string> list = new List<string>(deletes.Count);
List<string> list2 = new List<string>(deletes.Count);
foreach (KeyValuePair<DAODataSet, string> pair in deletes)
{
key = pair.Key;
foreach (DAODataTable table in key.DAODataTables)
{
str = str + "delete from " + table.Name + " where ";
if (table.Level)
{
str = str + table.RelKey;
}
else
{
str = str + table.Key;
list.Add(table.Name);
list2.Add(pair.Value.ToString().Replace("'", ""));
}
str = str + " in (" + pair.Value + ");\r";
}
}
if (str != string.Empty)
{
DBConnection connection = new DBConnection(key.DataSource);
connection.Open();
IDbTransaction transaction = connection.BeginTrasaction();
try
{
IDbCommand command = connection.Connection.CreateCommand();
command.Transaction = transaction;
command.CommandText = str;
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
connection.CommitTransaction();
}
catch (Exception exception1)
{
exception = exception1;
connection.RollBackTransaction();
throw exception;
}
finally
{
connection.Close();
}
try
{
ITraceDb traceDB = GetTraceDB(key.DataSource);
if (TraceUtil.CanTraceLevel(TraceLevel.Deleted) && (traceDB != null))
{
traceDB.TraceOuterRemove(list.ToArray(), list2.ToArray(), "经由系统(可能是前台工作流完全删除)操作删除进行的记录,注意它并没有对子表的删除进行记录.");
traceDB.SaveTraceToDb();
}
}
catch (Exception exception2)
{
exception = exception2;
log.Error("进行删除的痕迹记录出错:", exception);
}
}
}
catch (Exception exception3)
{
exception = exception3;
throw new DataFormException("delete data raise error!", exception);
}
}
示例5: Initial
public static void Initial(SMDataSource smDS, IList<DAODataTable> ddts, bool onlyTopLevel, string[] keys, string[] fields, IList<string[]> vals)
{
Exception exception;
ITraceDb traceDB = GetTraceDB(smDS);
bool canTraceAdd = TraceUtil.CanTraceLevel(TraceLevel.Added) && (traceDB != null);
StringBuilder builder = new StringBuilder();
foreach (DAODataTable table in ddts)
{
if (!onlyTopLevel || !table.Level)
{
string str = CreateInsertTableSQL(keys, fields, vals, traceDB, canTraceAdd, table);
if (!string.IsNullOrEmpty(str))
{
builder.Append(str).Append("\r\n");
}
}
}
if (builder.Length > 0)
{
DBConnection dbcn = new DBConnection(smDS);
dbcn.Open();
try
{
Execute(dbcn, builder.ToString(), null);
}
catch (Exception exception1)
{
exception = exception1;
throw new DataFormException("Initial data raise error", exception);
}
finally
{
dbcn.Close();
}
}
if (canTraceAdd)
{
try
{
traceDB.SaveTraceToDb();
}
catch (Exception exception2)
{
exception = exception2;
log.Error("系统对新增数据进行痕记录时出错:", exception);
}
}
}
示例6: QueryTrace
protected override DataTable QueryTrace(string table, string field, string keyValue)
{
DataTable table3;
StringBuilder builder = new StringBuilder(100);
builder.Append("select * from ").Append(TraceUtil.TraceTableName);
builder.Append(" \r where ").Append(TraceUtil.FLD_TABLE).Append("='").Append(table);
builder.Append("' \r and ").Append(TraceUtil.FLD_FIELD).Append("='").Append(field);
builder.Append("' \r and ").Append(TraceUtil.FLD_KEY).Append("='").Append(keyValue);
builder.Append("' \r order by ").Append(TraceUtil.FLD_TIMESTAMP);
DBConnection connection = new DBConnection(base.SMDataSource);
connection.Open();
try
{
DataTable dt = new DataTable();
connection.ExecuteSql(dt, builder.ToString());
table3 = dt;
}
finally
{
connection.Close();
}
return table3;
}
示例7: initDatabaseConnection
private void initDatabaseConnection( DBConnection connection )
{
if( connection.DatabaseInfo.SecondaryDatabaseName.Any()
? secondaryDatabasesWithInitializedConnections.Contains( connection.DatabaseInfo.SecondaryDatabaseName )
: primaryDatabaseConnectionInitialized )
return;
connection.Open();
if( DataAccessStatics.DatabaseShouldHaveAutomaticTransactions( connection.DatabaseInfo ) )
connection.BeginTransaction();
if( connection.DatabaseInfo.SecondaryDatabaseName.Any() )
secondaryDatabasesWithInitializedConnections.Add( connection.DatabaseInfo.SecondaryDatabaseName );
else
primaryDatabaseConnectionInitialized = true;
}
示例8: GetSchemaTable
private DataTable GetSchemaTable()
{
DataTable schemaTable;
DBConnection connection = new DBConnection(this.daoDataTable.TempletDataSet.DataSource);
connection.Open();
try
{
IDbCommand command = connection.Connection.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = "select * from " + this.daoDataTable.Name + " where 1<>1";
IDataReader reader = command.ExecuteReader();
try
{
schemaTable = reader.GetSchemaTable();
}
finally
{
reader.Close();
}
}
catch (Exception exception)
{
throw exception;
}
finally
{
connection.Close();
}
return schemaTable;
}
示例9: SaveDataToSQlDB
private void SaveDataToSQlDB(SMDataSource smDS, ref DataTable dt)
{
DBConnection connection = new DBConnection(smDS);
connection.Open();
try
{
IDbTransaction transaction = connection.BeginTrasaction();
DataTable dataTable = dt;
if (dataTable.GetChanges() != null)
{
string strSelect = (string) dataTable.ExtendedProperties["selectsql"];
DbDataAdapter adapter = connection.GetDataAdapter(strSelect, true, true, true);
try
{
adapter.Update(dataTable);
}
catch (DBConcurrencyException exception)
{
throw new DataFormException(exception.Message, exception);
}
}
connection.CommitTransaction();
}
catch (Exception exception2)
{
connection.RollBackTransaction();
throw exception2;
}
finally
{
connection.Close();
}
dt = this.RefreshDataset(smDS, dt);
}