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


C# NpgsqlConnection.Dispose方法代码示例

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


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

示例1: Empty

 public void Empty()
 {
     var connection = new NpgsqlConnection(ConnectionString);
     try
     {
         connection.Open();
         foreach (var tablename in StoreInfo.Tables)
         {
             using (var command = connection.CreateCommand())
             {
                 command.CommandType = CommandType.Text;
                 command.CommandText = [email protected]"delete from {tablename};";
                 command.ExecuteNonQuery();
             }
         }
     }
     catch (NpgsqlException exception)
     {
         throw new Exception($"Could not delete all from table {StoreInfo.Name}; see the inner exception for more information.", exception);
     }
     finally
     {
         connection.Dispose();
     }
 }
开发者ID:abaxas,项目名称:elephanet,代码行数:25,代码来源:Store.cs

示例2: Connection_Test

 public static bool Connection_Test(ENTITE.Serveur bean)
 {
     if (bean.Control_())
     {
         NpgsqlConnection con = new NpgsqlConnection();
         try
         {
             string constr = "PORT=" + bean.getPort + ";TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE= 2.0.14.3;DATABASE=" + bean.getDatabase + ";HOST=" + bean.getAdresse + ";PASSWORD=" + bean.getPassword + ";USER ID=" + bean.getUser + "";
             con = new NpgsqlConnection(constr);
             con.Open();
             return true;
         }
         catch (NpgsqlException ex)
         {
             Messages.Exception(ex);
             return false;
         }
         finally
         {
             con.Close();
             con.Dispose();
         }
     }
     return false;
 }
开发者ID:dowesw,项目名称:GESTION_CAISSE,代码行数:25,代码来源:Connexion.cs

示例3: Destroy

        public void Destroy()
        {
              var connection = new NpgsqlConnection(_connectionString);
              try
              {
                   connection.Open();
                  foreach (var tablename in StoreInfo.Tables)
                  {
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = String.Format(@"drop table {0};", tablename);
                        command.ExecuteNonQuery();
                    }
                  }
              } 

              catch (NpgsqlException exception)
              {
                    throw new Exception(String.Format("Could not drop table {0}; see the inner exception for more information.", _storeInfo.Name), exception);
              }

              finally
              {
                    connection.Dispose();
              }
        }
开发者ID:jmkelly,项目名称:elephanet,代码行数:27,代码来源:Store.cs

示例4: ExecuteScript

 private static void ExecuteScript(string filepath)
 {
     NpgsqlConnection conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["Postgres"].ToString());
     FileInfo file = new FileInfo(filepath);
     string script = file.OpenText().ReadToEnd();
     NpgsqlCommand cmd = new NpgsqlCommand(script, conn);
     conn.Open();
     cmd.ExecuteNonQuery();
     conn.Close();
     conn.Dispose();
 }
开发者ID:ysminnpu,项目名称:OpenLawOffice,代码行数:11,代码来源:Setup.cs

示例5: PgMalDataLoader

 public PgMalDataLoader(string connectionString)
 {
     m_conn = new NpgsqlConnection(connectionString);
     try
     {
         Logging.Log.Debug("Connecting to PostgreSQL.");
         m_conn.Open();
         Logging.Log.Debug("Connected to PostgreSQL.");
     }
     catch
     {
         m_conn.Dispose();
         throw;
     }
 }
开发者ID:mageomageos,项目名称:animerecs,代码行数:15,代码来源:PgMalDataLoader.cs

示例6: ConnectWithPool

 public void ConnectWithPool()
 {
     NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder(Conn.ConnectionString);
     csb.Pooling = true;
     String conStr = csb.ConnectionString;
     using (var metrics = TestMetrics.Start(TestRunTime, true))
     {
         while (!metrics.TimesUp)
         {
             var con = new NpgsqlConnection(conStr);
             con.Open();
             con.Dispose();
             metrics.IncrementIterations();
         }
     }
 }
开发者ID:kristofen,项目名称:Npgsql,代码行数:16,代码来源:SpeedTests.cs

示例7: CheckHealth

 /// <summary>
 /// Check that a connection can be established to Postgresql and return the server version
 /// </summary>
 /// <param name="connectionString">An Npgsql connection string</param>
 /// <returns>A <see cref="HealthResponse"/> object that contains the return status of this health check</returns>
 public static HealthResponse CheckHealth(string connectionString)
 {
     try
     {
         NpgsqlConnection conn = new NpgsqlConnection(connectionString);
         conn.Open();
         string host = conn.Host;
         string version = conn.PostgreSqlVersion.ToString();
         int port = conn.Port;
         conn.Close();
         conn.Dispose();
         return HealthResponse.Healthy(new { host = host, port = port , version = version});
     }
     catch (Exception e)
     {
         return HealthResponse.Unhealthy(e);
     }
 }
开发者ID:lynxx131,项目名称:dotnet.microservice,代码行数:23,代码来源:PostgresqlHealthCheck.cs

示例8: Deconnection

 public static void Deconnection(NpgsqlConnection con)
 {
     if (con != null)
     {
         try
         {
             con.Close();
             con.Dispose();
         }
         catch (NpgsqlException ex)
         {
             Messages.Exception(ex);
         }
         finally
         {
             con = null;
         }
     }
 }
开发者ID:dowesw,项目名称:GESTION_CAISSE,代码行数:19,代码来源:Connexion.cs

示例9: GlobalRegistration

        public void GlobalRegistration()
        {
            NpgsqlConnection.RegisterEnumGlobally<Mood>();
            var myconn = new NpgsqlConnection(ConnectionString);
            myconn.Open();
            const Mood expected = Mood.Ok;
            var cmd = new NpgsqlCommand("SELECT @p::MOOD", myconn);
            var p = new NpgsqlParameter { ParameterName = "p", Value = expected };
            cmd.Parameters.Add(p);
            var reader = cmd.ExecuteReader();
            reader.Read();

            Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Mood)));
            Assert.That(reader.GetFieldValue<Mood>(0), Is.EqualTo(expected));
            Assert.That(reader.GetValue(0), Is.EqualTo(expected));

            reader.Close();
            cmd.Dispose();
            myconn.Dispose();
        }
开发者ID:Emill,项目名称:Npgsql,代码行数:20,代码来源:EnumTests.cs

示例10: GetConnectionState

        public void GetConnectionState()
        {
            // Test created to PR #164

            NpgsqlConnection c = new NpgsqlConnection();
            c.Dispose();

            Assert.AreEqual(ConnectionState.Closed, c.State);



        }
开发者ID:timoch,项目名称:Npgsql-fdb,代码行数:12,代码来源:ConnectionTests.cs

示例11: ConnectionCreate

 /// <summary>
 /// 
 /// </summary>
 /// <param name="db"></param>
 /// <param name="cn"></param>
 /// <param name="com"></param>
 private static void ConnectionCreate(string db, out NpgsqlConnection cn, out NpgsqlCommand com)
 {
     Npgsql_Class npgsql_class = new Npgsql_Class();
         String connectionString = npgsql_class.connectionstring(db);
         cn = new NpgsqlConnection(connectionString);
         if (cn.State.ToString() == "Open")
         {
             cn.Close();
             cn.Dispose();
         }
         cn.Open();
         com = cn.CreateCommand();
 }
开发者ID:Geoneer,项目名称:GeoExplorer,代码行数:19,代码来源:Npgsql.cs

示例12: Connect

		private void Connect ()
		{
			try {
				string connectionString = String.Format("Server={0};Database={1};User ID={2};Password={3};",
					Configuration.DatabaseHost,
					Configuration.DatabaseName,
					Configuration.DatabaseUser,
					Configuration.DatabasePassword
				);
				if (Configuration.DatabasePort != 0)
					connectionString += string.Format ("Port={0};", Configuration.DatabasePort);

				dbcon = new NpgsqlConnection (connectionString);

				log.DebugFormat ("Connecting to database, connection string: {0}", connectionString);

				dbcon.Open ();

				object db_now_obj = ExecuteScalar ("SELECT now();");
				DateTime db_now;
				DateTime machine_now = DateTime.Now;

				db_now = (DateTime) db_now_obj;
				db_time_difference = db_now - machine_now;

				log.DebugFormat ("DB now: {0:yyyy/MM/dd HH:mm:ss.ffff}, current machine's now: {1:yyyy/MM/dd HH:mm:ss.ffff}, adjusted now: {3}, diff: {2:yyyy/MM/dd HH:mm:ss.ffff} ms", db_now, machine_now, db_time_difference.TotalMilliseconds, Now);
			} catch (Exception) {
				if (dbcon != null) {
					dbcon.Dispose ();
					dbcon = null;
				}
				throw;
			}
		}
开发者ID:joewstroman,项目名称:monkeywrench,代码行数:34,代码来源:DB.cs

示例13: lock

        PostgresTableMetadata IPostgresStore.GetOrCreateTable(Type type)
        {
            lock (_lock)
            {
                if (_tables.ContainsKey(type))
                {
                    return _tables[type];
                }

                var table = new PostgresTableMetadata(type);

                var connection = new NpgsqlConnection(_connectionString);
                try
                {
                    connection.Open();

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = String.Format(@"
                            CREATE TABLE IF NOT EXISTS public.{0}
                            (
                                id uuid NOT NULL DEFAULT md5(random()::text || clock_timestamp()::text)::uuid,
                                body json NOT NULL,
                                created timestamp without time zone NOT NULL DEFAULT now(),
                                row_version integer NOT NULL DEFAULT 1,
                                CONSTRAINT pk_{0} PRIMARY KEY (id)
                            );", table.Name);
                        command.ExecuteNonQuery();
                    }
                }
                catch (NpgsqlException exception)
                {
                    throw new Exception(String.Format("Could not create table {0}; see the inner exception for more information.", table.Name), exception);
                }
                finally
                {
                    connection.Dispose();
                }

                _tables[type] = table;
                return table;
            }
        }
开发者ID:sandcastle,项目名称:Stored,代码行数:44,代码来源:PostgresStore.cs

示例14: Connect

		private void Connect ()
		{
			try {
				string connectionString;

				connectionString = "Server=" + Configuration.DatabaseHost + ";";
				connectionString += "Database=builder;User ID=builder;";

				if (!string.IsNullOrEmpty (Configuration.DatabasePort))
					connectionString += "Port=" + Configuration.DatabasePort + ";";

				dbcon = new NpgsqlConnection (connectionString);

				Logger.Log (2, "Database connection string: {0}", connectionString);

				dbcon.Open ();

				object db_now_obj = ExecuteScalar ("SELECT now();");
				DateTime db_now;
				DateTime machine_now = DateTime.Now;
				const string format = "yyyy/MM/dd HH:mm:ss.ffff";

				if (db_now_obj is DateTime) {
					db_now = (DateTime) db_now_obj;
				} else {
					Logger.Log ("now () function return value of type: {0}", db_now_obj == null ? "null" : db_now_obj.GetType ().FullName);
					db_now = machine_now;
				}

				db_time_difference = db_now - machine_now;

				Logger.Log (2, "DB now: {0}, current machine's now: {1}, adjusted now: {3}, diff: {2} ms", db_now.ToString (format), machine_now.ToString (format), db_time_difference.TotalMilliseconds, Now.ToString (format));
			} catch {
				if (dbcon != null) {
					dbcon.Dispose ();
					dbcon = null;
				}
				throw;
			}
		}
开发者ID:DavidS,项目名称:monkeywrench,代码行数:40,代码来源:DB.cs

示例15: GetTransactionEventsUsingQuery

        private IEnumerable<TransactionEvent> GetTransactionEventsUsingQuery(NpgsqlCommand command)
        {
            NpgsqlConnection connection = null;
            NpgsqlDataReader reader = null;

            try
            {
                connection = new NpgsqlConnection(_connectionString);
                connection.Open();
                command.Connection = connection;
                reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        yield return GetTransactionEventFromRecord(reader);
                    }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }

                if (command != null)
                {
                    command.Dispose();
                }

                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            } 
        }
开发者ID:sjlbos,项目名称:SENG462_DTS,代码行数:39,代码来源:PostgresAuditRepository.cs


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