//Function cancelled public static bool ViewAttachment(string sql, string bp_id) { using (SqlCommand cmd = new SqlCommand(sql)) { cmd.Parameters.AddWithValue("@bp_id", bp_id); // Use an SqlDataReader so that we can write out the blob data in chunks. using (SqlDataReader reader = DbUtil.execute_reader(cmd, CommandBehavior.CloseConnection | CommandBehavior.SequentialAccess)) { if (reader.Read()) // Did we find the content in the database? { return(true); } } } return(false); }
protected void Page_Load(object sender, EventArgs e) { var sql = new SQLString("select us_id, us_email, us_username from users"); using (var reader = DbUtil.execute_reader(sql, System.Data.CommandBehavior.Default)) { while (reader.Read()) { var id = reader.GetInt32(0); var updateQuery = new SQLString("update users set password_reset_key=@resetKey where us_id = @id"); updateQuery.AddParameterWithValue("@id", id); var resetKey = Util.GenerateRandomString(); updateQuery.AddParameterWithValue("@resetKey", resetKey); var emailAddress = reader.IsDBNull(1) ? "" : reader.GetString(1); var username = reader.GetString(2); DbUtil.execute_nonquery(updateQuery); SendMail(emailAddress, resetKey, username); } } }
/////////////////////////////////////////////////////////////////////// public static BugPostAttachment get_bug_post_attachment(int bp_id) { // Note that this method does not perform any security check. // This is left up to the caller. string upload_folder = Util.get_upload_folder(); string sql; bool store_attachments_in_database = (Util.get_setting("StoreAttachmentsInDatabase", "0") == "1"); int bugid; string file; int content_length; string content_type; Stream content = null; try { sql = @"select bp_bug, bp_file, bp_size, bp_content_type from bug_posts where bp_id = $bp" ; sql = sql.Replace("$bp", Convert.ToString(bp_id)); using (SqlDataReader reader = DbUtil.execute_reader(sql, CommandBehavior.CloseConnection)) { if (reader.Read()) { bugid = reader.GetInt32(reader.GetOrdinal("bp_bug")); file = reader.GetString(reader.GetOrdinal("bp_file")); content_length = reader.GetInt32(reader.GetOrdinal("bp_size")); content_type = reader.GetString(reader.GetOrdinal("bp_content_type")); } else { throw new Exception("Existing bug post not found."); } } sql = @"select bpa_content from bug_post_attachments where bpa_post = $bp" ; sql = sql.Replace("$bp", Convert.ToString(bp_id)); object content_object; content_object = DbUtil.execute_scalar(sql); if (content_object != null && !Convert.IsDBNull(content_object)) { content = new MemoryStream((byte[])content_object); } else { // Could not find in bug_post_attachments. Try the upload_folder. if (upload_folder == null) { throw new Exception("The attachment could not be found in the database and UploadFolder is not set in web.config."); } string upload_folder_filename = upload_folder + "\\" + bugid + "_" + bp_id + "_" + file; if (File.Exists(upload_folder_filename)) { content = new FileStream(upload_folder_filename, FileMode.Open, FileAccess.Read, FileShare.Read); } else { throw new Exception("Attachment not found in database or UploadFolder."); } } return(new BugPostAttachment(file, content, content_length, content_type)); } catch { if (content != null) { content.Dispose(); } throw; } }