If you retrieve a reference to a particular virtual directory, you might want to investigate or modify the directory's properties. And if you create a new virtual directory, you must set at least some of its properties so that your new virtual directory can provide the functionality you need.
Table 3, page 60, shows the members that SQL Server 2000's ISQLVDir object (which represents a virtual directory and its properties) provides along with the members' associated dialog box options. I've listed the members in the order that their associated options appear in the Virtual Directory Properties dialog box. A property or value for each option is available in the dialog box. Read the information in this table carefully to understand the interactions between values for such properties as SecurityMode, UserName, Password, and EnablePasswordSync. (For additional member settings and other recent updates, you can download XML for Microsoft SQL Server 2000 Web Release 2 beta 1 at http://msdn.microsoft.com/downloads/default.asp?url=/code/sample.asp?url=/msdn-files/027/001/602/msdncompositedoc.xml.)
To create a new virtual directory named nwind, you might write code like Listing 2, page 61, shows. Your administrator might not let VB applications run on your server. In such a situation, you can use VBScript. Web Listing 1, available online, shows an example of the code in Listing 2 converted to VBScript. (For information about how to download listings, see "More on the Web, page 61.")
The nwind virtual directory is associated with the Northwind sample database; the code adds username and password settings and allows only the available types of queries. This code doesn't, however, add virtual names to your new virtual directory, which you'll need in most real applications. Note that this code sets the AllowFlags property to 0 while it's creating the virtual directory so that no one can access the directory until all the settings are complete. (For further details about setting up nwind, see the Microsoft article "Creating the nwind Virtual Directory" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_xml1_2xvd.asp.)
Adding Virtual Names
If you want your application to be able to use an XML template query or if you want to supply an XML schema that allows XPath queries against the XML data that SQL Server returns, you need to set up virtual names as part of your virtual directory. SQL Server supports three types of virtual names: template, schema, and dbobject. The template virtual name lets you specify the path to a folder associated with templates. Using this virtual name, you can run a template query from a URL by typing a URL like the one below:
http://iisserver/nwind/templatevirtualname/template.xml
This URL specifies the virtual name associated with the template instead of the physical path to the folder. (Note that a virtual name can also specify a template directlythat is, you don't need to append a filename.) The same rules apply to creating virtual names for schemas. You use the dbobject virtual name to instruct SQL Server 2000 to retrieve data directly from the database. (For more information about virtual names and their uses, see "Using IIS Virtual Directory Management for SQL Server Utility" in SQL Server 2000 BOL.)
To add virtual names to your virtual directory, you use members of the collection object that the VirtualNames property of a ISQLVDir object returns. Table 4 shows members of the VirtualNames collection object. Just as the collection returned by the SQLVDirs property does, this collection contains some members that you won't use from within VB. If you turn on the display of hidden members in VB's object browser, you'll find the Clone, Next, Reset, and Skip methods, which you need only if you're using scripting languages that don't support the For...Each...Next loop construct.
The AddVirtualName method returns a VirtualName object, although you'll rarely need to use that object because you've set all its properties in your call to the AddVirtualName method. If, however, you want to iterate through all the virtual names that a virtual directory contains, you might use a VirtualName object to control the loop.
To code the finished procedure that creates the sample nwind virtual directory and its three virtual names, add the following lines to the code at callout A in Listing 2:
With .VirtualNames
.AddVirtualName "Templates", vtTEMPLATE, conPath
.AddVirtualName "Schemas", vtSCHEMA, conPath
.AddVirtualName "Objects", vtDBOBJECT, ""
End With
You can specify the same path for the virtual directory and for its template and schema virtual name (i.e., you don't have to specify separate folders). But you can't specify a path for the vtDBOBJECT virtual name; doing so will trigger a runtime error.
A Simple Object Model
That's all there is to using the SQLVDir object model, whose objects and members give you all the tools you need to automate the management of your SQL Server 2000 virtual directories. Code that handles all these tasks is a great addition to your applications' installations, and the time you spend writing the code will certainly be less than an installation visit to each client or a phone call to each site.
End of Article
Prev. page
1
[2]
next page -->