本文整理汇总了C#中DBConnector.OpenConnection方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnector.OpenConnection方法的具体用法?C# DBConnector.OpenConnection怎么用?C# DBConnector.OpenConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnector
的用法示例。
在下文中一共展示了DBConnector.OpenConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoBackup
public static IEnumerator<string> DoBackup()
{
foreach (var dbElem in Config.GetElement("Databases").Elements()) {
if (dbElem.Element("Backup") == null) continue;
var dbName = dbElem.Name.ToString();
yield return dbName.ToString();
var db = new DBConnector(dbElem);
var backupPath = Environment.ExpandEnvironmentVariables(
String.Format(CultureInfo.InvariantCulture, dbElem.Element("Backup").Attribute("Path").Value, DateTime.Now)
);
Directory.CreateDirectory(Path.GetDirectoryName(backupPath));
using (var dataSet = new DataSet(dbName) { Locale = CultureInfo.InvariantCulture })
using (var original = db.OpenConnection()) {
List<string> tableNames;
using (var reader = original.ExecuteReader("SELECT QUOTENAME(s.name) + '.' + QUOTENAME(o.name) FROM sys.objects o JOIN sys.schemas s ON o.schema_id = s.schema_id WHERE type = 'U'")) {
tableNames = reader.Cast<IDataRecord>()
.Select(dr => dr.GetString(0))
.ToList();
}
foreach (var name in tableNames) {
using (var adapter = DB.Default.Factory.CreateDataAdapter(original, "SELECT * FROM " + name)) {
adapter.TableMappings.Add("Table", name);
adapter.Fill(dataSet);
}
}
using (var stream = new GZipStream(File.Create(backupPath), CompressionMode.Compress)) {
dataSet.WriteXml(stream, XmlWriteMode.WriteSchema);
}
}
if (Directory.GetFiles(Path.GetDirectoryName(backupPath))
.Except(new[] { backupPath })
.Any(p => Program.AreEqual(backupPath, p)))
File.Delete(backupPath);
}
}
示例2: ExternalDataManager
public ExternalDataManager(DBConnector db, DbConnection connection = null)
{
this.db = db;
this.Connection = connection ?? db.OpenConnection();
tables = GetTables();
}
示例3: using
///<summary>Gets the נר למאור sponsors for the given month, if any.</summary>
public static ReadOnlyCollection<SponsorshipInfo> Forנרלמאור(DBConnector db, DateTime date)
{
using (var connection = db.OpenConnection())
return Forנרלמאור(connection, date);
}
示例4: ReadSchemas
public static IEnumerable<SchemaModel> ReadSchemas(DataContextModel owner, DBConnector database)
{
if (database == null) throw new ArgumentNullException("database");
List<SchemaModel> tables = new List<SchemaModel>();
List<Action> postColumnActions = new List<Action>();
Func<string, string, SchemaModel> Table = (schema, name) => //First look for a new table from SQL Server, then for an existing one.
String.IsNullOrEmpty(name) ? null : tables.SingleOrDefault(t => t.SqlSchemaName == schema && t.SqlName == name)
?? owner.Schemas.SingleOrDefault(t => t.SqlSchemaName == schema && t.SqlName == name);
using (var connection = database.OpenConnection()) {
#region Read Tables
using (var reader = database.ExecuteReader(TablesSql)) {
while (reader.Read()) {
var table = new SchemaModel(owner) {
Name = (string)reader["TableName"],
SqlName = (string)reader["TableName"],
SqlSchemaName = reader["SchemaName"] as string
};
if (Table(table.SqlSchemaName, table.SqlName) != null) continue; //TODO: Import column
string keyName = reader["PrimaryKeyName"] as string;
if (!String.IsNullOrEmpty(keyName)) {
postColumnActions.Add(
() => table.PrimaryKey = table.Columns.Single(c => c.SqlName == keyName)
);
}
tables.Add(table);
}
}
#endregion
using (var reader = database.ExecuteReader(ColumnsSql)) {
while (reader.Read()) {
var table = Table((string)reader["SchemaName"], (string)reader["TableName"]);
if (table == null) continue; //Skip tables without RowVersion columns
var name = (string)reader["ColumnName"];
if (table.Columns.Any(c => c.SqlName == name))
continue; //Don't add duplicate columns to existing tables.
table.Columns.Add(new ColumnModel(table) {
Name = name,
SqlName = name,
DataType = SqlTypes[(string)reader["DataType"]],
AllowNulls = 1 == (int)reader["AllowNulls"],
IsUnique = 1 == (int)reader["IsUnique"],
ForeignSchema = Table(reader["ForeignSchema"] as string, reader["ForeignTable"] as string)
});
}
}
}
postColumnActions.ForEach(a => a());
return tables;
}