SQLDMO Apps - 3.2 Get Server Folder Information

xiaoxiao2021-03-06  102

3.2 Get server folder information

We often need to get the folder structure information of the server. For example, the server is operated directly on the client to back up server data, or restore data. We need to choose to back up the file to which directory below, or choose to restore backups from that directory. Similar to this situation, here is not listed here, I will introduce how to use SQLDMO to get the folder information of the server.

We can get information from EnumavailableMedia (SqldMaMedia_fixedDisk) to get information under the subfolder under the current path through EnumDirectories (String Pathname). This information is returned to the QueryResults interface. Of course, we must first connect SQLSerVLASS objects to the database to be these methods.

Below is some descriptions of the above two methods:

l EnumavailableMedia (SqldMo.sqldMo_Media_TYPE): Enumeral to SQL Server, the parameter is an enumeration type, used to specify the type returned by the method, namely

u SqldMomedia_all Returns all types

u SqldMomedia_cdrom Returns the light drive list

u SqldMomedia_FixedDisk Returns a list of hard drives

u SqldMomedia_FLOPPY Return to the floppical list

u SqldMOMEDIA_SHAREDFIXEDDISK Return to Shared Hard Disk List

u sqldMomedia_tape Returns a list of tape devices

l EnumDirectories: Get the subfolder information, the parameter is the current folder path, returns a list of subfolders.

The following code demonstrates how to obtain server folder information:

public

Class

CSserveInfo

{Sqldmo.sqlserverclass isterver = null; / ** ////

/// true Representation connection /// BOOL ISCONNECTED = false; / ** /// /// connection Server /// /// server name /// password /// true connection is successful public bool connect (string ServerName, string username, string password) {try {oServer = new SQLDMO.SQLServerClass (); oServer.Connect (ServerName, Username, Password); isconnected = true; returnne;} catch {i (erver! = Null) {iserver.disconnect (); oserver = null;} Return False;}} / ** //// < Summa RY> /// Get server root folder list /// /// root folder list public arraylist getrootdirs () {arraylist altemp = new arraylist (); if (iSconnected) {SQLDMO.QueryResults qRs = oServer.EnumAvailableMedia (SQLDMO.SQLDMO_MEDIA_TYPE.SQLDMOMedia_FixedDisk); for (int i = 1; i

} Return AlTemp;} else {return null;}} / ** ////

/// Get all subfolders list /// /// current path /// A list of subfolders public ArrayList GetSubDirs (string currentPath) {ArrayList alDirectories = new ArrayList (); if (isConnected) {SQLDMO.QueryResults qRs = oServer .Enumdirector (currentpath); for (int i = 1; i
转载请注明原文地址:https://www.9cbs.com/read-103496.html

New Post(0)