B ackup MSSQL DB & save to disk or email, user friendly app

H ey hey, One more exciting B Log;)

To continue the tradition of breaking promise, which I made in my last post about; “Giving you a small visual studio solution, using extJS4 as front end which consumes web services”. Well, This post does not contain what I promised for, but has something interesting and useful 🙂

Why I am sharing it?

Well, I think, every bit of sharing knowledge and expertise is “better than keeping it just to self”. You expand your knowledge-base by sharing it.

So, In the spirit of sharing and continued tradition of broken promise;

What I am sharing?

Backup and email the sql database

Here, I present you a with very small, lightweight c# win-forms application; Which uses the windows authentication to login(As currently, logged in user to windows) to the localhost database, connects to the default instance of SQL SERVER (MSSQLSERVER)

This utility is mainly used to backup the MSSQL database and save it to disk and to stretch things a little more, it will send zipped backup as attachment to an email, using your Hotmail or Gmail account. Code as supplied, DOES NOT CONTAIN logic to store PASSWORD OR EMAIL IN ANY FORM.

Who benefits from this application?

Developer, Why? because as a developer, I personally felt the task of taking database backup; using management studio as tedious and slightly overkill (I know this is not something that you do everyday, but you feel that you are dealing with so many options and dialogs when you just wanted to “Take a full database backup”)

May be not right for DBA, Why? because DBA would like more options with backups. And as “Rule of simplicity”, I choose to not cater for other options (Doesn’t mean, I am stopping you from doing it :p , be brave and explore)

Everyone else May be/May not be, because no one else cares about database, and this application is too techie for everyone else (tell me about it)

Nuts and bolts of this application?

Language used; c#, winforms

Uses T-SQL to execute Backup command on the selected database:

[sourcecode language=”csharp” ]
These driving forces then cause our body to deliver a healthy erection. tadalafil 40mg Erection issue is observed when there is lack of blood supply to the penile region can be a major cause which can be due to the physiological and psychological factors that slows the flow of blood in tadalafil canadian pharmacy loved that the penile. Tongkat Ali: prescription for ordering viagra It is a tropical aphrodisiac which originates in Malaysia. Booster capsules are viagra free samples the best herbal supplements to prevent soft erection. try
using (SqlConnection sqlConn = new SqlConnection(cnst_default_connectionstring))
string tSqlString = String.Format(@”BACKUP DATABASE [{0}] TO DISK = N'{1}’ WITH NOFORMAT, INIT, NAME = N'{0}-Full Database Backup’, SKIP, NOREWIND, NOUNLOAD, STATS = 10″, _selectedDatabase, _selectedBackupPath);
SqlCommand sqlCommand = new SqlCommand(tSqlString) { Connection = sqlConn };

and Uses System.IO.Compression to compress the backup,
and Uses System.Net.Mail and SmtpClient to attach compressed backup and send email

For now, you can only use “Gmail” or “Hotmail/live” account to use as from email account.

SQLBackupAndEmail – Source code

SQLBackupAndEmail – Demo application

If you have any questions, I am more than happy to answer them 🙂

I am not making another promise to break it, but, All, I can say is “Watch this space !!”