当前位置: 首页>>代码示例>>C#>>正文


C# DBConnector.OpenConnection方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:ShomreiTorah,项目名称:Utilities,代码行数:41,代码来源:DbBackup.cs

示例2: ExternalDataManager

 public ExternalDataManager(DBConnector db, DbConnection connection = null)
 {
     this.db = db;
     this.Connection = connection ?? db.OpenConnection();
     tables = GetTables();
 }
开发者ID:ShomreiTorah,项目名称:Utilities,代码行数:6,代码来源:ExternalDataManager.cs

示例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);
 }
开发者ID:ShomreiTorah,项目名称:Libraries,代码行数:6,代码来源:SponsorshipInfo.cs

示例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;
        }
开发者ID:ShomreiTorah,项目名称:Utilities,代码行数:62,代码来源:SqlReader.cs


注:本文中的DBConnector.OpenConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。