Wednesday, June 17, 2009

MS SQL Database database backup

How to Create a Backup in SQL Server 2005?

This is the query for create a SQL server backup

BACKUP DATABASE [data_base_name] --Name of the database
TO DISK = N'F:\Backups\BackOffic.bak' --Location to save backup file
WITH NOFORMAT, --Specifies that the backup operation preserves the existing media header and backup sets on the media volumes used for this backup operation
INIT, --Specifies that all backup sets should be overwritten
NAME = N'Mye-Full Database Backup'
, --Name of the backup file
SKIP, --Disables the checking of backup set expiration and name that is usually performed by the BACKUP statement to prevent overwrites of backup sets.
NOREWIND, --Specifies that SQL Server will keep the tape open after the backup operation
NOUNLOAD, --Specifies that after the BACKUP operation the tape will remain loaded on the tape drive.
STATS = 10
--Displays a message each time another percentage completes (displays a message after each 10 percent is completed.)

Friday, June 12, 2009

Sending an email in ASP.Net using C#

C# Code for sending  an email in ASP.Net

You can use following code to send an email in using C#

public bool SendMail()
string SERVER = txtSMTP.Text;

MailMessage objMsg = new MailMessage();
int port = 25;//SMTP port number
objMsg.BodyFormat = MailFormat.Text;
objMsg.To = "";

objMsg.From = "yourmail@yourdomain";
objMsg.Cc = "";
objMsg.Subject = "Sending E-Mails using C#";

string userName = "";
string password = "123";
int cdoBasic = 1;
int cdoSendUsingPort = 2;

objMsg.Fields.Add("", SERVER);
objMsg.Fields.Add("", port);
objMsg.Fields.Add("", userName);
objMsg.Fields.Add("", password);
objMsg.Fields.Add("", cdoSendUsingPort);
objMsg.Fields.Add("", cdoBasic);

objMsg.Body = "This is the message body";

//If mail has an attatchment
if (FileUpload1.HasFile)

string filename = Server.MapPath("") + "\\userfiles\\" + FileUpload1.FileName;

objMsg.Attachments.Add(new MailAttachment(filename));

SmtpMail.SmtpServer = SERVER;

return true;
catch (Exception ex)
ShowMessage("Mail Sending Fail");
return false;