Initialization
The virtual device interface is implemented as a set of Component Object Model (COM) interfaces. An application gains access to the interface by standard COM methods. First, the application must initialize the COM environment for multithreading:
CoInitializeEx (NULL, COINIT_MULTITHREADED);
Once COM is initialized, then the application creates an instance of an interface:
CoCreateInstance (CLSID_MSSQL_ClientVirtualDeviceSet, NULL, CLSCTX_INPROC_SERVER, IID_IClientVirtualDeviceSet2,&vds))
Sample code accompanies this documentation. Browsing over this code may help you understand the details covered in this document. If you don't have the sample code, you can download it from Microsoft.com.
The client uses IClientVirtualDeviceSet2::CreateEx to give a unique system-wide name to the virtual device set and establish some basic configuration information, such as the number of devices. The client then issues a BACKUP or RESTORE command through ODBC or an alternative. However, rather than specifying disk or tape the keyword VIRTUAL_DEVICE should be used. If more than one device is to be used, then the command must have one VIRTUAL_DEVICE clause for each device. The first VIRTUAL_DEVICE clause must specify the exact name given on the IClientVirtualDeviceSet2::CreateEx invocation. Subsequent clauses name each additional virtual device within the set. The only restriction on these names is that they be unique within the set. For example, if three devices were specified, a BACKUP command might look like:
BACKUP DATABASE MYDB
TO VIRTUAL_DEVICE='{0D0F5BA0-B21A-4519-A961-A6E2292A17CA}',
VIRTUAL_DEVICE='dev2', VIRTUAL_DEVICE='dev3'
To ensure uniqueness, it is recommended that a GUID be used as the name of the virtual device set. The sample code uses this approach. However, clients are free to use any scheme they wish.
Note Usually the same number of devices is used during both RESTORE and BACKUP. However, for removable media, it is possible to use fewer devices. In that case, after each data stream has been read, SQL Server requests a new, unprocessed data stream by issuing a mount request. For more information about media sets, backup sets, and media families, see Microsoft SQL Server Books Online.