.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

BackUp by C#

Posted By:Nikhil Kumar       Posted Date: January 12, 2010    Points: 10    Category: File Operation    URL: http://www.dotnetspark.com  

This tool allows you to backup your database by selecting the sever name and all at run time :) and its written in C#.

BackUp Software
Namespaces... which u will indclude...... 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

private void btnConnect_Click(object sender, EventArgs e)

//Coding which u will on the click event of connect button... 
                if (cmbsrv_name.SelectedItem != null && cmbsrv_name.SelectedItem.ToString() != "")
                    ServerConnection srvcon = new ServerConnection(cmbsrv_name.SelectedItem.ToString());
                    srvcon.LoginSecure = false;
                    srvcon.Login = txtuserid.Text;
                    srvcon.Password = txtPassword.Text;
                    srv = new Server(srvcon);
                    foreach (Database db in srv.Databases)
                    MessageBox.Show("Please select a server first", "Server Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            catch (Exception ex)

If u are running sql by windows auth....
then remove login and password and type Integrated security = true;
 type this code on the click event of backup button after conneted to the sql...

and for full suppot please download this file...


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend