|
|
Why relative filespecs may not work in ASP
Use ADO's native OLEDB drivers instead of ODBC
Quickly determine client browser types in JavaScript code
Generate accurate ADO RecordCount values in ASP
Use a single ADO connection to reduce ASP server load
Register WSC scripts before using them in ASP
Obtain a header list with ASP's ServerVariables collection
Create Visual InterDev 6.0 ASP code templates
A caveat when using ASP's Response.Redirect method
Simplify loading stored values via ASP
Convert ADO fields to XML tags without errors
Syntax requirements for integrating XSL into ASP and HTML
Configure IIS from DOS in Windows 2000
Cumulative patches for IIS 4.0/5.0/5.1 released at Microsoft
How to determine which version of the .NET Framework you're running
Even though the helpfile states you can use relative directory paths with FileSystemObject objects, you probably encountered an error if you tried to use them in an ASP path. That's because the directory that contains the ASP page doesn't become the current directory, as far as the FileSystemObject is concerned. To illustrate, run the following VBScript code in an ASP page:
<%
Set FileObject = Server.CreateObject ("Scripting.FileSystemObject")
filespec="\test.jpg"
CurrDir = FileObject.GetAbsolutePathName(".")
response.write "Using CurrDir: " & CurrDir & filespec & "<br>"
if FileObject.FileExists(filespec) then
response.write "[CurrDir] File Found<br>"
else
response.write "[CurrDir] No File found<br>"
end if
response.write "Using MapPath: " & Server.MapPath(filespec) & "<BR>"
if FileObject.FileExists(Server.MapPath(filespec)) then
response.write "[MapPath] File Found<br>"
else
response.write "[MapPath] No File found<br>"
end if
Set FileObject = Nothing
%>
Submitted by: Michael Harris
| UP |
When you create an connection string, ADO gives you a choice between indicating a data source driver as either a Driver, as in
Driver={SQL Server};DBQ=database_file
or a Provider, such as
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database_name
However, when you use the first option, ADO uses older ODBC drivers to connect to the data source; whereas the second form uses OLEDB, which is ADO's native data access interface. For this reason, you should use the Provider option whenever possible. Such native OLEDB drivers exist for SQL Server, Index Server, Site Server Search, and Oracle, among others.
| UP |
The document object model and ASP pages offer several ways to determine a client's browser type. Most, however involve long parsing routines that search for specific substrings within a larger string. Fortunately, using JavaScript, there's a quick way to determine if the client browser is either Netscape Navigator 4+ or Internet Explorer 4+. The basic idea is that you test for objects in the browser's DOM that don't exist in the other browser's DOM. For example, IE 4.0 + browsers include the document.all collection, while NN4.0 + browsers support the document.layers collection. If one of these objects is null, then your code can infer that the client is the other browser type. For example, the following script displays the boolean results of each test when you load a Web page:
<script language="JavaScript">
var nav4 = !(document.layers == null)
var iex4 = !(document.all == null)
alert("Nav: " + nav4 + " IE4: " + iex4)
</script>
As you can see, the first expression sets the nav4 variable equal to the opposite of document.layers==null. So, if you view this page in an IE 4+ browser, document.layers is null, and the entire expression evaluates to false.
| UP |
As you know, the ADO RecordCount property returns the number of records in an ADO recordset. Of course, in several instances, this property also returns a -1 instead. The value RecordCount returns depends on the recordset's cursor type: -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.
You may be surprised to learn that RecordCount will be -1 for recordsets created with the Execute method from a Connection or Command object. That's because this method generates a forward-only recordset, which, as we mentioned earlier, returns -1.
As an example, enter and run the following procedure in a standard ASP page. When you open it, the page displays -1 for the recordset based on myConRst, and 6246 for myKeyRst.
<%
Dim myConn, myComm, myConRst, myKeyRst
Dim sConnection
sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\Microsoft Visual Studio\VB98\Biblio.mdb"
Set myConn = Server.CreateObject("ADODB.Connection")
Set myKeyRst = Server.CreateObject("ADODB.Recordset")
myConn.Open sConnection
myComm = "Select * From Authors"
Set myConRst = myConn.Execute(myComm, , 1)
myKeyRst.Open myComm, myConn, 1
%>
RecCount <BR>
>From Connection: <%=myConRst.RecordCount%><BR>
>From Recordset: <%=myKeyRst.RecordCount%>
<%
Set myKeyRst = Nothing
Set myConRst = Nothing
Set myConn = Nothing
%>
| UP |
If you need to execute multiple SQL statements on a single database in a single ASP page, it's often wise to open a single Connection and reuse it multiple times. Doing so reduces the number of times the server must open and close the same database, which can significantly increase the server's load. To use a single connection, create the database Connection at the beginning of the page, then destroy it at the end. When you Execute a SQL statement, whether it returns a Recordset or not, specify the active Connection. Here's an example:
<%
strDSN = "DSN=database;UID=username;PWD=password"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strDSN
strSQL = "select column from table"
Set rsResults=conn.Execute(strSQL, , 1)
if not rsResults.eof then
temp = rsResults("column")
else
temp = "No Results"
end if
'close the Recordset, but leave the Connection open
rsResults.Close
strSQL = "delete from table where column=123"
conn.Execute strSQL, , 1
'Done executing SQL statements at this point, so close the Connection.
conn.Close
set rsResults = Nothing
set conn = Nothing
%>
Submitted by: Brian Coverstone [brian@pcioh.com]
| UP |
The Windows Scripting Component is a great tool that let's you create COM components for use in ASP pages. What's more, you can use either VBScript or JavaScript to give them functionality. When you create a WSC component, however, you must register it before you can use it in an ASP page. To do so, open Windows Explorer and right-click on the WSC file you just created. Select Register from the shortcut menu. To create an object variable based on the new script object, use code similar to
Set objXMLCreate = Server.CreateObject("MyScriptObj.WSC")
At this point, you're free to access any of the object's methods and properties.
| UP |
The SeverVariables collection contains all kinds of information about the calling client and the server. For instance, you can determine a visitor's browser type with the HTTP_USER_AGENT variable. Or, you can use HTTP_REFERER to determine the referring Internet address. Not all browsers support the same headers, however. To see a quick list of the headers supported within a browser, run the following code.
<HTML>
<BODY>
<TABLE BORDER=1>
<TH COLSPAN=2>ServerVariables</TH>
<%
For Each var in Request.ServerVariables
With Response
.Write("<TR>")
.Write("< TD><B>" & var & "</B> :</TD>")
.Write("<TD>") & Request.ServerVariables(var) _
& "</TD>")
.Write("</TR>")
End With
Next
%>
</TABLE>
</BODY>
</HTML>
| UP |
Instead of retyping the same code lines on virtually every ASP page that you create in Visual InterDev 6.0, simply open Program Files | Microsoft Visual Studio | VIntDev98 | Templates | Web Project Items | New ASP Page.asp file, and then enter the code that you want duplicated, i.e. included files, titles, metatags. Save your work, and any new ASP page that you create will contain the new code.
Submitted by: Will Smith [will@newtweb.com]
| UP |
When ASP encounters the Response or End methods, it immediately halts script execution in both the GLOBAL.ASA file and in the application page. As a result, ASP won't execute any script that follows the Redirect method. Instead, it either ends the session or begins processing the new page. For this reason, you should always make the Redirect method the last call in any script.
| UP |
When loading an <OPTIONS> list from a database table, it's much easier to call a procedure that uses process parameters. This way, you can use the same procedure for several different operations. For example, suppose you want to fill a Listbox with a list of animals. In addition, you've set up several checkboxes on a Web page that let the user simply view the list, or load the list with one of the animals already selected. The following example shows how you might process the resulting page. (To save space, we hard-coded the two parameters.)
<!-- #include File="DBConnect.Asp" --> <HTML> <BODY> <FORM> <SELECT name=Atype size= 5>
<% Dim chkMode chkMode = 2 'or Request.Form("chkMode") fillOptionList chkMode,"Snake" %>
</SELECT>
<% Sub fillOptionList(myMode, optionValue)
Dim rsAnimal Dim strSelected
set rsAnimal = CreateObject("ADODB.recordset") With rsAnimal .Open "tblAnimals", strDB, adOpenStatic,,adCmdTable
Do While Not .EOF
Select Case myMode
Case 1 strSelected = "" Case Else If optionValue = rsAnimal("Animal") Then strSelected = " SELECTED" Else strSelected = "" End if End Select
Response.Write("<OPTION" & strSelected & " VALUE=" _
& rsAnimal("ID") & ">" & rsAnimal("Animal") & "</OPTION>")
.MoveNext
Loop
.Close
End With
Set rsAnimal = Nothing
End Sub
%>
</BODY>
</HTML>
For the OPTION elements, this code produces output HTML like this:
<SELECT name=Atype size= 5>
<OPTION Value=1>Cat</OPTION> <OPTION Value=2>Cow</OPTION> <OPTION Value=3>Dog</OPTION> <OPTION SELECTED Value=4>Snake</OPTION> <OPTION Value=5>Elephant</OPTION> <OPTION Value=6>Fish</OPTION>
</SELECT>
Submitted by: Faisal Ladak
[fladak@systech-inc.net]
| UP |
XML tag names can't contain several special characters or spaces. Therefore, when you use ADO field names as XML tags, make sure to rename the fields, if necessary, in the SQL statement. For example, if you use the following SQL statement:
Select [Employ ID], Name FROM Employees
and then use XMLDOM to convert the recordset fields into XML, the XML document will generate an error. That's because XMLDOM's creation methods convert the [Employ ID] fieldname into <Employ ID>. However, the space is an invalid character. To avoid this error, use an alias name in the SQL string, such as:
Select [Employ ID] AS EmployID, Name FROM Employees
| UP |
Since an XSL stylesheet is an XML document itself, its markup must conform to XML grammar rules. Most notably, you must ensure that you close all tags. Since HTML is considerably more forgiving in this regard, make sure that the markup in XSL sheets will successfully parse. For example, to use <BR> to express a line break, you must enter <BR> instead. To read more about the W3's recommendation for XHTML, which addresses this issue, see http://www.w3.org/TR/xhtml1/
| UP |
Windows 2000 provides a wealth of IIS management and administrative scripts that you can use from the DOS command prompt. Among other things, you can search your Web server for a virtual Web site, display a tree of the structure of your IIS server, create Web sites and virtual directories, start and stop services, and more. Take a look at the following URL for more information:http://support.microsoft.com/view/tn.asp?kb=308622
| UP |
As you know, keeping your Web server up-to-date with the latest patches and security fixes can be a real challenge. Fortunately, Microsoft recently released a cumulative patch that saves you a lot of trouble. For IIS 4.0, the patch includes all fixes released since Windows NT 4.0 Service Pack 6a. For IIS 5.0 and 5.1, the patch includes all fixes released to date. Period. Navigate to the following URL to download and install this critical product update:www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/MS02-018.asp
| UP |
Since the .NET Framework itself is just a collection of classes and structures, you might wonder where to look to determine the exact version, including installed service packs, of the Framework you've got. This is especially true when you inherit responsibility for a machine running .NET. Here's where to look:For Windows 2000 and XP, you need to run the .NET Framework Configuration MMC snap-in. On Windows XP, this is tucked away under Administrative Tools on the Start menu. For Windows 2000, you'll have to manually add it to a running instance of MMC. In either case, choose Help | About from the snap-in menu, and you'll see which version you've got to work with. For Windows 98, Me, and NT 4.0, you'll need to download this snap-in from Microsoft, since it isn't installed by default. Get it at http://download.microsoft.com/download/platformsdk/Install/1.2.0/W9XNT4Me/EN-US/IMMC.EXE.
| UP |
|
|