Sqldmo (SQL distributed management objects, SQL distributed management object) is a group of COM components developed by Ms.
// Retrieve Server LIST
Private Arraylist getserverlist ()
{
System. Collections. arraylist alservers = New System. Collections. arraylist ();
Sqldmo. Application sqlapp = New Sqldmo. applicationclass ();
Try
{
Sqldmo. namelist serverlist = Sqlapp. listavailablesqlservers ();
For ( Int I = 1 ; I <= Serverlist. Count; I ++ )
{
Alservers. Add (serverlist. Item (I ));
}
}
Catch (Exception E)
{
Throw(NewException ("An error occurred while retrieving the database server list:"+E. Message ));
}
Finally
{
Sqlapp. Quit ();
}
Return Alservers;
}
// Obtain the Database List on the server
Private Bool Getdblist ( String Strservername, String Strusername, String Strpwd)
{
Bool Bolreturn = False ;
Arraylist aldbs = New Arraylist ();
Sqldmo. Application sqlapp = New Sqldmo. applicationclass ();
Sqldmo. svr SVR = New Sqldmo. sqlserverclass ();
Try
{
SVR. Connect (strservername, strusername, strpwd );
Foreach (Sqldmo. Database DB In SVR. databases)
{
If(Db. Name! =Null)
Aldbs. Add (db. Name );
}
This . Cmbdb. datasource = Aldbs;
Bolreturn = True ;
}
Catch (Exception E)
{
Throw(NewException ("Database Connection error:"+E. Message ));
}
Finally
{
SVR. Disconnect ();
Sqlapp. Quit ();
}
Return Bolreturn;
}
// Database Backup
Private Void Dbbackup ( String Savepath, String Database)
{
Sqldmo. svr SVR = New Sqldmo. sqlserverclass ();
Try
{
SVR. Connect ( This . Server, This . Userid, This . Password );
Sqldmo. Backup Bak = New Sqldmo. backupclass ();
Sqldmo. backupsink_percentcompleteeventhandler pceh = New Sqldmo. backupsink_percentcompleteeventhandler (setbarvisible );
Bak. percentcomplete + = Pceh;
Bak. Action = Sqldmo. sqldmo_backup_type.sqldmobackup_database;
Bak. initialize = True ;
Bak. Files = Savepath + @" \ 1.bak " ;
Bak. Database = Database;
Bak. sqlbackup (SVR );
}
Catch (System. Exception XX)
{
Throw(NewException ("Database Backup failed" +XX. Message ));
}
Finally
{
SVR. Disconnect ();
}
}