Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PostgreSaver : IDbSaver
- {
- public PostgreSaver()
- {
- npgsqlConnection = new NpgsqlConnection();
- NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder();
- builder.Host = "10.10.1.11";
- builder.Port = 5432;
- builder.UserName = "postgres";
- builder.Password = "123";
- npgsqlConnection.ConnectionString = builder.ConnectionString;
- npgsqlConnection.Open();
- }
- public void Save(WebLog webLog)
- {
- NpgsqlCommand command = new NpgsqlCommand();
- command.CommandText = "insert into ping(ping_id, name, url, ip) values(nextval('seq_ping'), @name, @url, @ip)";
- command.Parameters.Add(new NpgsqlParameter("name", webLog.Name));
- command.Parameters.Add(new NpgsqlParameter("url", webLog.Url));
- command.Parameters.Add(new NpgsqlParameter("ip", webLog.Ip));
- command.Connection = npgsqlConnection;
- command.ExecuteNonQuery();
- }
- private NpgsqlConnection npgsqlConnection;
- }
Add Comment
Please, Sign In to add comment