Пример #1
0
        public IList<Server> GetServers(int sinceId)
        {
            var results = new List<Server>();

            using (var cn = new SqlConnection(_configuration.DatabaseConnectionString))
            {
                using (var cmd = new SqlCommand(GetLatestServersQuery, cn))
                {
                    cn.Open();
                    cmd.CommandTimeout = _configuration.QueryTimeout;
                    cmd.Parameters.Add("@SinceId", SqlDbType.Int).Value = sinceId;
                    
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var server = new Server();
                        server.Id = (int)reader[0];
                        server.Name = reader[1].ToString();

                        results.Add(server);
                    }
                }
            }

            return results;
        }
Пример #2
0
 public void Add(Server server)
 {
     using (var cn = new SqlConnection(_configuration.DatabaseConnectionString))
     {
         using (var cmd = new SqlCommand(InsertQuery, cn))
         {
             cmd.CommandTimeout = _configuration.QueryTimeout;
             cmd.Parameters.Add("@ServerName", SqlDbType.VarChar, 200).Value = server.Name;
             cn.Open();
             cmd.ExecuteNonQuery();
         }
     }
 }