daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PostgreSaver : IDbSaver
  2.     {
  3.         public PostgreSaver()
  4.         {
  5.             npgsqlConnection = new NpgsqlConnection();
  6.             NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder();
  7.             builder.Host = "10.10.1.11";
  8.             builder.Port = 5432;
  9.             builder.UserName = "postgres";
  10.             builder.Password = "123";
  11.             npgsqlConnection.ConnectionString = builder.ConnectionString;
  12.             npgsqlConnection.Open();
  13.         }
  14.  
  15.         public void Save(WebLog webLog)
  16.         {
  17.             NpgsqlCommand command = new NpgsqlCommand();
  18.             command.CommandText = "insert into ping(ping_id, name, url, ip) values(nextval('seq_ping'), @name, @url, @ip)";
  19.             command.Parameters.Add(new NpgsqlParameter("name", webLog.Name));
  20.             command.Parameters.Add(new NpgsqlParameter("url", webLog.Url));
  21.             command.Parameters.Add(new NpgsqlParameter("ip", webLog.Ip));
  22.             command.Connection = npgsqlConnection;
  23.             command.ExecuteNonQuery();
  24.         }
  25.  
  26.         private NpgsqlConnection npgsqlConnection;
  27.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top