how to clean/shrink a database log file ?

Posted by gondar | Filed under , , ,

many times our databases log files, increase so much that they very often have 5 times or more than database size.

one of the things we can do, is shrink the log file, wich will clean all operation we made with the database that are saved, for security proposes.

ex.: database products

DBCC SHRINKFILE('products_log', 1)
BACKUP LOG products WITH TRUNCATE_ONLY DBCC SHRINKFILE('products_log', 1)

this, will set the actuall size of the database to 1Mb :)

it´s simple

hope it helps

 

how to send a email? (using MailMessage)

Posted by gondar | Filed under

to use the mailmessage to send emails, 1 we need to add:

using System.Net.Mail;
using System.Net;

and then instantiate a new mailmessage class, and then use the following to send a simple mail

MailMessage mail = new MailMessage();
mail.From = new MailAddress("__from_email__");
mail.To.Add("__to_email__");
mail.Subject = "Subject here";
mail.Body = "Message here";
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient("__smtp__");
smtp.Send(mail);

some email providers doesn´t accept an email if it doesn´t have credentials, so we must specify it, it accepts any valid email (and password) that you have, so we need the following:

smtp.Credentials = new NetworkCredential("__email__", "__password__");

and then the complete code is:

MailMessage mail = new MailMessage();
mail.From = new MailAddress("__from_email__");
mail.To.Add("__to_email__");
mail.Subject = "Erro --> Geco";
mail.Body = "Utilizador: ";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("__smtp__");
smtp.Credentials = new NetworkCredential("__email__", "__password__");
smtp.Send(mail);

hope it helps