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


C# Database.Dispose方法代码示例

本文整理汇总了C#中Database.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Dispose方法的具体用法?C# Database.Dispose怎么用?C# Database.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnlockDatabase

		public bool UnlockDatabase(string pin)
        {
            try
            {
				loginAttempts++;

				database = new Database(databasePath, pin);

				loginAttempts = 0;
				return true;
            }
			catch (SQLiteException ex)
            {
				Insights.Report(ex);
				if (loginAttempts >= 5) 
				{
					//5x foutieve pincode ingevoerd dus verwijder geregistreerde localboxen
					DeleteDatabase ();
				}

                if (database != null)
                    database.Dispose();
                database = null;
                return false;
            }
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:26,代码来源:DataLayer.cs

示例2: ConstructorWithConnectionDBTypeAndIsolationLevel

        public void ConstructorWithConnectionDBTypeAndIsolationLevel()
        {
            var db = new Database(TestDatabase.Connection, new SqlServer2012DatabaseType(), IsolationLevel.ReadUncommitted);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(typeof(SqlServer2012DatabaseType), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNotNull(db.Connection);

            db.Dispose();
            Assert.IsNotNull(db.Connection);
        }
开发者ID:robertmilne,项目名称:NPoco,代码行数:15,代码来源:ConstructorTests.cs

示例3: ConstructorWithConnection

        public void ConstructorWithConnection()
        {
            var db = new Database(TestDatabase.Connection);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(typeof (SqlServerDatabaseType), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNotNull(db.Connection);

            db.Dispose();
            Assert.IsNotNull(db.Connection);
        }
开发者ID:robertmilne,项目名称:NPoco,代码行数:15,代码来源:ConstructorTests.cs

示例4: ConstructorWithConnectionStringAndDBProvider

        public void ConstructorWithConnectionStringAndDBProvider()
        {
            var dbType = new SqlServer2012DatabaseType();
            var provider = DbProviderFactories.GetFactory(dbType.GetProviderName());
            var db = new Database(TestDatabase.ConnectionString, provider);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(typeof(SqlServerDatabaseType), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNull(db.Connection);

            db.Dispose();
            Assert.IsNull(db.Connection);
        }
开发者ID:robertmilne,项目名称:NPoco,代码行数:17,代码来源:ConstructorTests.cs

示例5: ConstructorWithConnectionStringDBProviderAndSettings

        public void ConstructorWithConnectionStringDBProviderAndSettings()
        {
            var dbType = GetConfiguredDatabaseType();
            var provider = DbProviderFactories.GetFactory(dbType.GetProviderName());
            var db = new Database(TestDatabase.ConnectionString, provider, false);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(dbType.GetType(), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNull(db.Connection);

            db.Dispose();
            Assert.IsNull(db.Connection);
        }
开发者ID:aalex675,项目名称:NPoco,代码行数:17,代码来源:ConstructorTests.cs

示例6: ConstructorWithConnectionStringDBTypeAndSettings

        public void ConstructorWithConnectionStringDBTypeAndSettings()
        {
            var dbType = GetConfiguredDatabaseType();
            var db = new Database(TestDatabase.ConnectionString, dbType, IsolationLevel.ReadUncommitted, false);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(dbType.GetType(), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNull(db.Connection);

            db.Dispose();
            Assert.IsNull(db.Connection);
        }
开发者ID:aalex675,项目名称:NPoco,代码行数:16,代码来源:ConstructorTests.cs

示例7: TransactionSettingsDontCauseLocksAndTransationRollback

        public void TransactionSettingsDontCauseLocksAndTransationRollback()
        {
            var nameInsert = "Name" + 16;
            var ageInsert = 20 + 16;
            var nameUpdate = "Name" + 99;
            var ageUpdate = 20 + 99;

            var user = new UserDecorated
            {
                Name = nameInsert,
                Age = ageInsert,
                DateOfBirth = new DateTime(1970, 1, 1).AddYears(16),
                Savings = 50.00m + (1.01m * 16)
            };
            Database.Insert(user);

            var userAfterCreate = Database.SingleOrDefault<UserDecorated>("WHERE UserID = @0", user.UserId);
            Assert.IsNotNull(userAfterCreate);
            Assert.AreEqual(userAfterCreate.Name, nameInsert);


            var dbTrans = new Database(TestDatabase.ConnectionString, TestDatabase.DbType);
            dbTrans.BeginTransaction();

            user.Name = nameUpdate;
            user.Age = ageUpdate;
            dbTrans.Update(user);

            // Verify inside of transaction
            var userPreCommitInside = dbTrans.SingleOrDefault<UserDecorated>("WHERE UserID = @0", user.UserId);
            Assert.IsNotNull(userPreCommitInside);
            Assert.AreEqual(nameUpdate, userPreCommitInside.Name);
            Assert.AreEqual(ageUpdate, userPreCommitInside.Age);

            dbTrans.AbortTransaction();
            dbTrans.Dispose();

            var userPostCommit = Database.SingleOrDefault<UserDecorated>("WHERE UserID = @0", user.UserId);
            Assert.IsNotNull(userPostCommit);
            Assert.AreEqual(nameInsert, userPostCommit.Name);
            Assert.AreEqual(ageInsert, userPostCommit.Age);
        }
开发者ID:aalex675,项目名称:NPoco,代码行数:42,代码来源:TransactionDecoratedTests.cs

示例8: ImportBlocks

        public void ImportBlocks()
        {
            
            AcadApp.DocumentCollection dm = AcadApp.Application.DocumentManager;
            Editor ed = dm.MdiActiveDocument.Editor;
            Database destDb = dm.MdiActiveDocument.Database;
            Database sourceDb = new Database(false, true);
            PromptResult sourceFileName;
            try
            {
                //从命令行要求用户输入以得到要导入的块所在的源DWG文件的名字
                sourceFileName = ed.GetString("\nEnter the name of the source drawing: ");
                //把源DWG读入辅助数据库
                sourceDb.ReadDwgFile(sourceFileName.StringResult, System.IO.FileShare.Write, true, "");
                //用集合变量来存储块ID的列表
                ObjectIdCollection blockIds = new ObjectIdCollection();
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
                sourceDb.TransactionManager;
                using (Transaction myT = tm.StartTransaction())
                {
                    //打开块表
                    BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId,
                    OpenMode.ForRead, false);
                    //在块表中检查每个块
                    foreach (ObjectId btrId in bt)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId,
                        OpenMode.ForRead, false);
                        //只添加有名块和非layout块(layout块是非MS和非PS的块) 
                        if (!btr.IsAnonymous && !btr.IsLayout)
                            blockIds.Add(btrId);
                        btr.Dispose();	//释放块表记录引用变量所占用的资源
                    }
                    bt.Dispose();//释放块表引用变量所占用的资源
                    //没有作改变,不需要提交事务
                    myT.Dispose();
                }
                
                IdMapping mapping = new IdMapping();
                mapping = sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, DuplicateRecordCloning.Replace, false);

                ed.WriteMessage("\nCopied " + blockIds.Count.ToString() + " block definitions from " + sourceFileName.StringResult + " to the current drawing.");
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("\nError during copy: " + ex.Message);
            }
            sourceDb.Dispose();
        }
开发者ID:freudshow,项目名称:raffles-codes,代码行数:49,代码来源:Class1.cs

示例9: IndexModule

        public IndexModule()
        {
            IDatabase db = new Database(ConfigurationManager.ConnectionStrings["db"].Name);

            Get["/"] = _ =>
            {
                //TODO: Maybe create some sort of dashboard? Worse case - just redirect to /sites?
                return Response.AsRedirect("/sites");
            };

            /// <summary>
            /// Retrieves all sites.
            /// </summary>
            Get["/sites"] = _ =>
            {
                List<Sites> sites = db.Fetch<Sites>();
                db.Dispose();

                Model = sites;

                return View["index", Model];
            };

            /// <summary>
            /// Retrieves a specific site
            /// </summary>
            Get["/sites/{siteId}"] = parameter =>
            {
                string Id = parameter.siteId;

                var site = db.FetchBy<Sites>(sql => sql.Where(x => x.SiteId == Id));

                List<Tags> AllTags = db.Fetch<Tags>().ToList();
                List<SiteTags> Tags = db.FetchBy<SiteTags>(sql => sql.Where(x => x.SiteId == Id)).ToList();

                List<Tags> tagList = AllTags.Where(allTags => Tags.Select(tags => tags.TagId).Contains(allTags.TagId)).ToList();

                bool firstCSV = true;
                StringBuilder tagsCSV = new StringBuilder();
                foreach (var tag in tagList)
                {
                    if (!firstCSV) { tagsCSV.Append(","); }
                    tagsCSV.Append(tag.TagName);
                    firstCSV = false;
                }

                Model.site = site;
                Model.tags = tagsCSV.ToString();

                db.Dispose();

                return View["update", Model];
            };

            Post["/sites/meta"] = parameter =>
            {

                string requestedUrl = string.Empty;
                if (Request.Form.Values.Count > 0)
                {
                    foreach (var i in Request.Form.Values)
                    {
                        if (!string.IsNullOrWhiteSpace(requestedUrl))
                        {
                            break;
                        }
                        requestedUrl = i;
                    }
                }

                if (UriChecker.IsValidURI(requestedUrl))
                {

                    SitesMeta metadata = GetMetaData(requestedUrl);
                    return Response.AsJson(metadata);
                }
                else
                {
                    return HttpStatusCode.BadRequest;
                }

            };

            /// <summary>
            /// Update a specific site
            /// </summary>
            Put["/sites/{siteId}"] = parameter =>
            {
                string Id = parameter.siteId;

                Sites snapshot = db.FetchBy<Sites>(sql => sql.Where(x => x.SiteId == Id)).FirstOrDefault();

                Sites site = this.Bind<Sites>();

                // Don't clear out fields existing fields.
                site.Active = snapshot.Active;
                site.DateTime = snapshot.DateTime;
                site.MetaTitle = snapshot.MetaTitle;
                site.MetaDescription = snapshot.MetaDescription;
                site.MetaKeywords = snapshot.MetaKeywords;
//.........这里部分代码省略.........
开发者ID:06b,项目名称:Dalian,代码行数:101,代码来源:IndexModule.cs

示例10: CheckIfBookmarkAlreadyExists

        /// <summary>
        /// Checks if bookmark already exists.
        /// </summary>
        /// <param name="Url">The URL.</param>
        public static bool CheckIfBookmarkAlreadyExists(string Url)
        {
            if (Url.EndsWith("/", StringComparison.Ordinal))
            {
                //If the Url ends with a slash remove it
                Url = Url.Substring(0, Url.Length - 1);
            }

            if (Url.StartsWith("http://", StringComparison.Ordinal))
            {
                //If Url starts with Http - Remove it
                Url = Url.Substring(7);
            }
            else
            {
                //If Url starts with Https - Remove it
                Url = Url.Substring(8);
            }

            var BookmarkWithHttpsWithoutSlash = "https://" + Url;
            var BookmarkWithHttpsWithSlash = "https://" + Url + "/";
            var BookmarkWithHttpWithoutSlash = "http://" + Url;
            var BookmarkWithHttpWithSlash = "http://" + Url + "/";

            IDatabase db = new Database(ConfigurationManager.ConnectionStrings["db"].Name);

            //Check if the current requested URL already exists in the database with multiple combinations
            var Bookmark = db.FetchBy<Sites>(sql => sql.Where(x => x.Url == BookmarkWithHttpsWithoutSlash || x.Url == BookmarkWithHttpsWithSlash || x.Url == BookmarkWithHttpWithoutSlash || x.Url == BookmarkWithHttpWithSlash)).ToList();
            db.Dispose();

            if (Bookmark.Count > 0)
            {
                //Bookmark exists
                return true;
            }

            //Bookmark doesn't exist "in theory"
            return false;
        }
开发者ID:06b,项目名称:Dalian,代码行数:43,代码来源:IndexModule.cs

示例11: ImportBlocks

            //[CommandMethod("IB")]
            public static void ImportBlocks()
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;
                Database destDb = doc.Database;
                Database sourceDb = new Database(false, true);

                String sourceFileName;

                try
                {
                    //Get name of DWG from which to copy blocks
                    sourceFileName = "C:\\Program Files\\AutoCAD MEP 2010\\DynaPrograms\\TagHgr.dwg";

                    //Read the DWG file into the database
                    sourceDb.ReadDwgFile(sourceFileName.ToString(), System.IO.FileShare.Read, true, "");

                    //Create a variable to store the list of block Identifiers
                    ObjectIdCollection blockIds = new ObjectIdCollection();

                    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;

                    using (Transaction myTm = tm.StartTransaction())
                    {
                        //Open the block table
                        BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);

                        //Check each block in the table
                        foreach (ObjectId btrId in bt)
                        {
                            BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false);

                            //Only add named and non-layout blocks to the copy file if the don't already exist.
                            if (!btr.IsAnonymous && !btr.IsLayout)
                                blockIds.Add(btrId);
                            btr.Dispose();
                        }
                    }
                    //Copy blocks from source to dest database
                    IdMapping mapping = new IdMapping();
                    sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
                    //Writes the number of blocks copied to cmd line.
                    //ed.WriteMessage("\nCopied: " + blockIds.Count.ToString() + " block definitions from " + sourceFileName + " to the current drawing.");

                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage(ex.Message);
                }
                sourceDb.Dispose();
            }
开发者ID:kmorin,项目名称:pointloadcalc,代码行数:52,代码来源:Class2.cs

示例12: ReturnDatabase

        internal static void ReturnDatabase(Database database)
        {
            lock (SyncRoot)
            {
                if (DatabasePools.Exists(db => db.Alias == database.Alias) && database.ReturnToPool)
                {
                    DatabasePool pool = DatabasePools.Find(q => q.Alias == database.Alias);

                    pool.Databases.Enqueue(database);
                }
                else
                {
                    database.Dispose();
                }
            }
        }
开发者ID:yojimbo87,项目名称:Eastern,代码行数:16,代码来源:EasternClient.cs

示例13: ImportBlocks

        public static void ImportBlocks()
        {
            using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                DocumentCollection dm = Application.DocumentManager;
                Editor ed = dm.MdiActiveDocument.Editor;
                Database destDb = dm.MdiActiveDocument.Database;
                Database sourceDb = new Database(false, true);
                try
                {
                    // Read the DWG into a side database
            #if DEBUG
                sourceDb.ReadDwgFile("../../88.dwg", System.IO.FileShare.Read, true,"");
            #else
                    sourceDb.ReadDwgFile("./Resource/88.dwg", System.IO.FileShare.Read, true, "");
            #endif
                    // Create a variable to store the list of block identifiers
                    ObjectIdCollection blockIds = new ObjectIdCollection();
                    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;
                    using (Transaction myT = tm.StartTransaction())
                    {
                        // Open the block table
                        BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);

                        // Check each block in the block table
                        foreach (ObjectId btrId in bt)
                        {
                            BlockTableRecord btr =
                              (BlockTableRecord)tm.GetObject(btrId,
                                                            OpenMode.ForRead,
                                                            false);
                            // Only add named & non-layout blocks to the copy list
                            if (!btr.IsAnonymous && !btr.IsLayout)
                                blockIds.Add(btrId);
                            btr.Dispose();
                        }
                    }
                    // Copy blocks from source to destination database
                    IdMapping mapping = new IdMapping();
                    sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage("\nError during copy: " + ex.Message);
                }
                sourceDb.Dispose();
            }
        }
开发者ID:FengLuanShuangWu,项目名称:AutoCADPlugin-HeatSource,代码行数:48,代码来源:Utility.cs

示例14: ConstructorWithConnectionStringAndProviderName

        public void ConstructorWithConnectionStringAndProviderName()
        {
            var dbType = GetConfiguredDatabaseType();
            var db = new Database(TestDatabase.ConnectionString, dbType, SqlClientFactory.Instance);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(dbType.GetType(), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNull(db.Connection);

            db.Dispose();
            Assert.IsNull(db.Connection);
        }
开发者ID:schotime,项目名称:NPoco,代码行数:16,代码来源:ConstructorTests.cs

示例15: ValidatePincode

        public Task<bool> ValidatePincode(string pincode)
        {
            return Task.Run(() =>
            {
                Database db = null;
                try
                {
                    db = new Database(databasePath, pincode);
                }
                catch (SQLiteException ex)
                {
					Insights.Report (ex);
                    return false;
                }
                finally
                {
                    if (db != null)
                        db.Dispose();
                }
                return true;
            });
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:22,代码来源:DataLayer.cs


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