public bool TryWriteValues(IEnumerable <KeyValuePair <UInt256, WriteValue <BlockHeader> > > values)
        {
            using (var conn = this.OpenConnection())
                using (var trans = conn.BeginTransaction())
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.Transaction = trans;

                        cmd.Parameters.Add(new FbParameter {
                            ParameterName = "@blockHash", FbDbType = FbDbType.Char, Charset = FbCharset.Octets, Size = 32
                        });
                        cmd.Parameters.Add(new FbParameter {
                            ParameterName = "@headerBytes", FbDbType = FbDbType.Char, Charset = FbCharset.Octets, Size = 80
                        });

                        cmd.CommandText = CREATE_QUERY;
                        foreach (var keyPair in values.Where(x => x.Value.IsCreate))
                        {
                            var blockHeader = keyPair.Value.Value;

                            var blockBytes = StorageEncoder.EncodeBlockHeader(blockHeader);
                            cmd.Parameters["@blockHash"].Value   = blockHeader.Hash.ToDbByteArray();
                            cmd.Parameters["@headerBytes"].Value = blockBytes;

                            cmd.ExecuteNonQuery();
                        }

                        cmd.CommandText = UPDATE_QUERY;
                        foreach (var keyPair in values.Where(x => !x.Value.IsCreate))
                        {
                            var blockHeader = keyPair.Value.Value;

                            var blockBytes = StorageEncoder.EncodeBlockHeader(blockHeader);
                            cmd.Parameters["@blockHash"].Value   = blockHeader.Hash.ToDbByteArray();
                            cmd.Parameters["@headerBytes"].Value = blockBytes;

                            cmd.ExecuteNonQuery();
                        }

                        trans.Commit();

                        return(true);
                    }
        }
        public bool TryWriteValues(IEnumerable <KeyValuePair <UInt256, WriteValue <BlockHeader> > > values)
        {
            try
            {
                using (var conn = this.OpenConnection())
                    using (var trans = conn.BeginTransaction())
                        using (var cmd = conn.CreateCommand())
                        {
                            // give writes low deadlock priority, a flush can always be retried
                            using (var deadlockCmd = conn.CreateCommand())
                            {
                                deadlockCmd.Transaction = trans;
                                deadlockCmd.CommandText = "SET DEADLOCK_PRIORITY LOW";
                                deadlockCmd.ExecuteNonQuery();
                            }

                            cmd.Transaction = trans;

                            cmd.Parameters.Add(new SqlParameter {
                                ParameterName = "@blockHash", SqlDbType = SqlDbType.Binary, Size = 32
                            });
                            cmd.Parameters.Add(new SqlParameter {
                                ParameterName = "@headerBytes", SqlDbType = SqlDbType.Binary, Size = 80
                            });

                            cmd.CommandText = CREATE_QUERY;
                            foreach (var keyPair in values.Where(x => x.Value.IsCreate))
                            {
                                var blockHeader = keyPair.Value.Value;

                                var blockBytes = StorageEncoder.EncodeBlockHeader(blockHeader);
                                cmd.Parameters["@blockHash"].Value   = blockHeader.Hash.ToDbByteArray();
                                cmd.Parameters["@headerBytes"].Value = blockBytes;

                                cmd.ExecuteNonQuery();
                            }

                            cmd.CommandText = UPDATE_QUERY;
                            foreach (var keyPair in values.Where(x => !x.Value.IsCreate))
                            {
                                var blockHeader = keyPair.Value.Value;

                                var blockBytes = StorageEncoder.EncodeBlockHeader(blockHeader);
                                cmd.Parameters["@blockHash"].Value   = blockHeader.Hash.ToDbByteArray();
                                cmd.Parameters["@headerBytes"].Value = blockBytes;

                                cmd.ExecuteNonQuery();
                            }

                            trans.Commit();

                            return(true);
                        }
            }
            catch (SqlException e)
            {
                if (e.IsDeadlock() || e.IsTimeout())
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }