Backup Utility In .Net

Backup Software

Namespaces, which u will include.

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;

Coding which u will on the click event of connect button.

private void btnConnect_Click(object sender, EventArgs e)
{
    try
    {
        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)
            {
                cmbDatabase.Items.Add(db.Name);
            }
        }
        else
        {
            MessageBox.Show("Please select a server first", "Server Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

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 a backup button after connecting to the SQL.

and for full support please download this file.


Similar Articles