. Net backup database

Source: Internet
Author: User

 

Sqldmo (SQL distributed management objects, SQL distributed management object) encapsulates Microsoft SQL Server 2000 Objects in the database. SQL - DMO allows you to write applications in languages that support automation or com.ProgramTo manage all parts installed on SQL Server. SQL - DMO is an SQL Server 2000 The application interface (API) used by the SQL Server Enterprise Manager in - DMO applications can execute all functions executed by the SQL Server Enterprise Manager.

SQL-DMO is used for any automated or com applications that must contain SQL Server Management. For example:
1. Encapsulate SQL Server as your data storage and try to reduce your SQL server management tasks.
2. The application itself is incorporated into a dedicated management logic.
3. You want to integrate the SQL server management task application in your user interface.

The sqldmo object comes from sqldmo. dll. sqldmo. dll is released along with SQL Server2000. Sqldmo. dll itself is a COM Object. Therefore, it must be referenced in your. Net project first.

 

Private   Void Button3_click ( Object Sender, system. eventargs E)
{
// Reference sqldmo. dll. sqldmo is provided by sqldmo. dll of Microsoft SQL Server, and sqldmo. dll is a COM object.
Sqldmo. Backup = New Sqldmo. backupclass ();
Sqldmo. sqlserver = New Sqldmo. sqlserverclass ();
Sqlserver. loginsecure = False ;
Sqlserver. Connect ( " Localhost " , " SA " , " 1 " );
Backup. Action = Sqldmo. sqldmo_backup_type.sqldmobackup_database;
Backup. Database = " Userdb " ;
Backup. Files = @" E: \ project \ Meng \ data \ userdb. Bak " ;
Backup. backupsetname = " Userdb " ;
Backup. backupsetdescription = " Database Backup " ;
Backup. initialize = True ;
Backup. sqlbackup (sqlserver );
}

Private   Void Button4_click ( Object Sender, system. eventargs E)
{
Sqldmo. Restore restore = New Sqldmo. restoreclass ();
Sqldmo. sqlserver = New Sqldmo. sqlserverclass ();
Sqlserver. loginsecure = False ;
Sqlserver. Connect ( " 192.168.19.25 " , " SA " , " SA " ); Restore. Action = Sqldmo. sqldmo_restore_type.sqldmorestore_database;
Restore. Database = " Userdb " ;
Restore. Files = @" E: \ project \ Meng \ data \ userdb. Bak " ;
Restore. backupsetname = " Userdb " ;
Restore. filenumber = 1 ;
Restore. sqlrestore (sqlserver );
}
// Obtains the list of all databases on the specified SQL Server.
Public Arraylist getdatabaselist ( String Servername, String Username, String PWD)
{
Arraylist list =   New Arraylist ();
Sqldmo. Application sqlapp =   New Sqldmo. Application ();
Sqldmo. sqlserver oserver =   New Sqldmo. sqlserver ();

Oserver. Connect (servername, username, PWD );
Foreach (Sqldmo. Database DB In Oserver. databases)
{
If (Db. Name ! = Null ) && (Db. systemobject =   False ))
List. Add (db. Name );
}
Return List;
}

// Obtain the SQL Server LIST
Public Arraylist getsqlserverlist ()
{
Arraylist list =   New Arraylist ();
Sqldmo. Application sqlapp =   New Sqldmo. Application ();
Sqldmo. namelist servername = Sqlapp. listavailablesqlservers ();
For ( Int I = 0 ; I < Servername. Count; I ++ )
{
List. Add (servername. Item (I + 1 ));
}
Return List;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.