<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Inspired? No &#187; ASP</title>
	<atom:link href="http://blog.inspired.no/category/asp/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.inspired.no</link>
	<description>Espen Antonsen writes about the web</description>
	<lastBuildDate>Tue, 13 Jul 2010 11:31:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ASP Performance Best Practices #2</title>
		<link>http://blog.inspired.no/asp-performance-best-practices-2-72</link>
		<comments>http://blog.inspired.no/asp-performance-best-practices-2-72#comments</comments>
		<pubDate>Thu, 30 Sep 2004 16:07:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[ADO]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/asp-performance-best-practices-2-72</guid>
		<description><![CDATA[This is the second post in my &#8216;ASP Performance Best Practices&#8217; series. Read the first post about using ADO GetRows() here. General ASP script tips: - Always buffer scripts. Are you still using Windows NT then turn on buffering in IIS &#8211; or enable buffering in each script by using: response.buffer = true. This is [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second post in my &#8216;ASP Performance Best Practices&#8217; series. <a href="/2004/09/asp-performance-best-practices-1.html">Read the first post about using ADO GetRows() here</a>.</p>
<p>General ASP script tips:</p>
<p>- Always buffer scripts. Are you still using Windows NT then turn on buffering in IIS &#8211; or enable buffering in each script by using: <a href="http://www.devguru.com/Technologies/asp/quickref/response_buffer.html">response.buffer = true</a>. This is not needed in Windows 2000/2003 because buffering is enabled by default.</p>
<p>- Always use <a href="http://www.devguru.com/Technologies/vbscript/quickref/optionexplicit.html">Option Explicit</a>.</p>
<p>- Don&#8217;t put objects in the application and session scope &#8211; unless you know what you are doing and that it is the best solution.</p>
<p>- minimize session variables. Consider alternatives such as cookies, store in database, save to harddisk.</p>
<p>- Don&#8217;t mix scripting languages.</p>
<p>- Don&#8217;t mix ASP and HTML. If you need to then include HTML in response.write&#8217;s.</p>
<p>- Keep files as small as possible. This means: Learn to code proper <a href="http://www.w3c.org">HTML using W3C standards</a>. Use CSS classes, no inline styles.</p>
<p>- Re-use code. Put common functions in global include files.</p>
<p>- Use COM objects instead of ASP whenever possible.</p>
<p>- Instead of normal ASP scripts use <a href="http://www.4guysfromrolla.com/webtech/092399-1.shtml">VBScript classes</a> (if you can&#8217;t use COM objects).</p>
<p>- Don&#8217;t request the same values over and over again. Example:</p>
<pre name="code" class="vb">if dbrs.fields("Drink").value = "Milk" Then
   Accept(false)
elseif dbrs.fields("Drink").value = "Water" Then
   SaveForLater()
elseif dbrs.fields("Drink").value = "Wine" Then
   CheckWineLabel()
elseif dbrs.fields("Drink").value = "Beer" Then
   do until drunk
       Drink()
       GetNewBeer()
   loop
else
   response.write "Unknown liquid"
end if</pre>
<p>Instead use:</p>
<pre name="code" class="vb">Dim value
value = dbrs.fields("Drink").value
If value = "Milk" Then .....</pre>
<p> </p>
<p> </p>
<p>- Explicitly set what you want to retrieve. Instead of:</p>
<pre name="code" class="vb">querystring_value = request("var1")
recordset_value = dbrs("Fieldname")</pre>
<p>use:</p>
<pre name="code" class="vb">querystring_value = request.querystring.item("var1")
recordset_value = dbrs.fields.item("Fieldname").value</pre>
<p>In some cases there will be a default property, but if not then ASP has to loop through all possible properties to find what you are looking for. In the case of the <a href="http://www.devguru.com/Technologies/asp/quickref/request.html">Request object</a>, ASP has to loop through the <a href="http://www.devguru.com/Technologies/asp/quickref/request_form.html">form</a>, <a href="http://www.devguru.com/Technologies/asp/quickref/request_querystring.html">querystring</a>, <a href="http://www.devguru.com/Technologies/asp/quickref/request_cookies.html">cookies</a>, <a href="http://www.devguru.com/Technologies/asp/quickref/request_certificate.html">clientCertificate </a>and <a href="http://www.devguru.com/Technologies/asp/quickref/request_servervariables.html">serverVariables </a>collections to find the variable. With ADO Recordset I am not sure if this is relevant, I think the fields collection is the default and the property collection is ignored &#8211; but I don&#8217;t know.</p>
<p>- Keep your code structured.</p>
<p>- Comment your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/asp-performance-best-practices-2-72/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UTF-8 with ASP</title>
		<link>http://blog.inspired.no/utf-8-with-asp-71</link>
		<comments>http://blog.inspired.no/utf-8-with-asp-71#comments</comments>
		<pubDate>Tue, 28 Sep 2004 18:38:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/utf-8-with-asp-71</guid>
		<description><![CDATA[I am currently working with internationalization of 24SevenOffice.com. We want to support languages like Chinese, Hungarian and even Right-To-Left languages like Arabic. To do so we must use Unicode. On the web the most common Unicode used it UTF-8. For a good introduction to Unicode, UTF-8 and other character sets read &#8216;The Absolute Minimum Every [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working with <a href="http://en.wikipedia.org/wiki/Internationalization">internationalization</a> of <a href="http://www.24sevenoffice.com/">24SevenOffice.com</a>. We want to support languages like Chinese, Hungarian and even Right-To-Left languages like Arabic. To do so we must use Unicode. On the web the most common Unicode used it UTF-8. For a good introduction to Unicode, UTF-8 and other character sets read &#8216;<a href="http://www.joelonsoftware.com/articles/Unicode.html">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a>&#8216; by <a href="http://www.joelonsoftware.com/">Joel Spolsky</a>. And also check out the <a href="http://www.unicode.org/">Unicode site</a> and <a href="http://www.i18nguy.com/">I18n Guy</a>.</p>
<p>In ASP and HTML there are a couple of things we must to do serve up UTF-8:</p>
<p>ASP CODE:</p>
<pre name="code" class="vb">Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"</pre>
<p>and the following HTML META tag:</p>
<pre name="code" class="html">&lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /&gt;</pre>
<p>We are using <a href="http://www.microsoft.com/sql/">Microsoft SQL Server</a> as a database. While it stores data as UCS-2 (Unicode) in Unicode fields (nchar/nvarchar/ntext), I have encountered problems with saving data in Chinese. It seems I have to use <a href="http://support.microsoft.com/?id=239530">N prefix</a> in front of all columns &#8211; i.e. UPDATE Table SET Field = N&#8217;Unicode Value&#8217;;. I am currently checking more around this issue. I really hope I don&#8217;t need to do this, if so I must say I am very disappointed with SQL Server &#8211; with Oracle this would not have been a problem.</p>
<p>For right-to-left languages we can use a<a href="http://www.devguru.com/Technologies/css/quickref/css_direction.html"> property in CSS called direction</a>, also you can read more about <a href="http://www.i18nguy.com/markup/right-to-left.html">Right-To-Left text in markup languages here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/utf-8-with-asp-71/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>ASP Performance Best Practices #1</title>
		<link>http://blog.inspired.no/asp-performance-best-practices-1-68</link>
		<comments>http://blog.inspired.no/asp-performance-best-practices-1-68#comments</comments>
		<pubDate>Sat, 11 Sep 2004 11:32:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[ADO]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/asp-performance-best-practices-1-68</guid>
		<description><![CDATA[Visiting ASP sites, forums and places like Expert Exchange, I see many examples of ASP code that will not result in good performance. I will make a list of tips on how to achieve good performance. These tips will include ASP (VBScript) coding techniques, SQL query/ADO/SQL Server optimization and alternative ways of doing things (XML, [...]]]></description>
			<content:encoded><![CDATA[<p>Visiting ASP sites, forums and places like <a href="http://www.experts-exchange.com/Web/Web_Languages/ASP/">Expert Exchange</a>, I see many examples of ASP code that will not result in good performance. I will make a list of tips on how to achieve good performance. These tips will include ASP (VBScript) coding techniques, SQL query/ADO/SQL Server optimization and alternative ways of doing things (XML, JavaScript on the client, DTS on SQL Server etc.). I am not a performance guru but experience and reading many articles with performance tips I have a good knowledge regarding this. If you have any better solutions than the tips here or if anything is not correct, please let me know.</p>
<p>First tip is the best way to get data from SQL Server. Most people use ADO Recordset and loop through it. This means you have a connection to the SQL Server open while executing the script. A much better way is to use the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthgetrows.asp">GetRows() function in ADO</a>:</p>
<pre name="code" class="vb">
Dim db, dbrs, sql, ConnString, users, user

ConnString = "DSN=YourDSN;"
sql = "SELECT UserId, Username FROM Users ORDER BY Username;"

' GET DATA
set db = server.createobject("ADODB.Connection")
db.open ConnString
set dbrs = server.createObject("ADODB.Recordset")
dbrs.open sql, db
if NOT dbrs.eof then
    users = dbrs.GetRows()
end if
db.close
set db = nothing

' DISPLAY DATA
for user = lbound(users,2) to ubound(users,2)
   response.write "UserId: " &#038; users(0,user)
   response.write "Username: " &#038; users(1,user)
   response.write vbNewLine
next
</pre>
<p>From the ADO Documentation:</p>
<blockquote><p>
<br />Use the GetRows method to copy records from a Recordset into a two-dimensional array. The first subscript identifies the field and the second identifies the record number. The array variable is automatically dimensioned to the correct size when the GetRows method returns the data.<br />
</p></blockquote>
<p>Since it&#8217;s a two-dimensional array we need to get the lower and upper bound of the array using: lbound(users,2). Using those values we loop from the first item to the last item.</p>
<p>The current record is the user variable. To get the field we want we must get it according to the index entered in the SQL Query:</p>
<p>SELECT UserId, Username..</p>
<p>UserId: 0<br />
<br />UserName: 1<br />
<br />and so on.</p>
<p>This can be confusing if you do changes to the SQL Query &#8211; then you must go through your code and update the array index for the fields! A solution to that is to create costants for each field name:</p>
<p><code><br />
<br />Dim UserId<br />
<br />Const UserId = 0<br />
<br /></code></p>
<p><span style="font-weight:bold;">Lessons learned:</span><br />

<ol>

<li>Use ADO GetRows() to get data.</li>
<p>
<li>Initiate objects as late as possible and release objects as early as possible.</li>
<p>
<li>Use variable for SQL query. Easier for debugging.</li>
<p>
<li>Declare all variables at the top of the script/function/class.</li>
<p></ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/asp-performance-best-practices-1-68/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get a file from another server</title>
		<link>http://blog.inspired.no/get-a-file-from-another-server-48</link>
		<comments>http://blog.inspired.no/get-a-file-from-another-server-48#comments</comments>
		<pubDate>Mon, 26 Jul 2004 11:03:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/get-a-file-from-another-server-48</guid>
		<description><![CDATA[The Microsoft XML Parser includes an object called XMLHTTP. Though the name says XML it has little to do with XML except for one function that makes it possible to retreive a document as XML. The essential use of XMLHTTP is to send HTTP requests and retrive the response. It is quite simple to use [...]]]></description>
			<content:encoded><![CDATA[<p>The Microsoft XML Parser includes an object called XMLHTTP. Though the name says XML it has little to do with XML except for one function that makes it possible to retreive a document as XML. The essential use of XMLHTTP is to send HTTP requests and retrive the response. It is quite simple to use and it&#8217;s very easy to do a simple task like get a file from another server:</p>
<pre name="code" class="javascript">
dim objXMLHTTP, url
set objXMLHTTP = server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
url = "http://yourserver.com/file.html"
objXMLHTTP.Open "GET", url, false
objXMLHTTP.Send()
response.Write objXMLHTTP.responseText
set objXMLHTTP = nothing
</pre>
<p>Note: This is for use with ASP. Notice the Server in the object. That&#8217;s the server-safe version of XMLHTTP. When using client-side JavaScript use the MSXML2.XMLHTTP.4.0 instead. Also remember that there are many versions of the XML Parser around, so don&#8217;t use the 4.0 version if the user doesn&#8217;t have it installed. I recommend using the MS XML Parser sniffer to get the correct version installed &#8211; <a href="/2004/06/microsoft-xml-parser-sniffer.html">see my article here</a>.</p>
<p><a href="http://www.perfectxml.com/msxmlHTTP.asp">See this page at PerfectXML for more information.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/get-a-file-from-another-server-48/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Error page on IIS and logging</title>
		<link>http://blog.inspired.no/custom-error-page-on-iis-and-logging-27</link>
		<comments>http://blog.inspired.no/custom-error-page-on-iis-and-logging-27#comments</comments>
		<pubDate>Wed, 16 Jun 2004 18:05:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[ADO]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/custom-error-page-on-iis-and-logging-27</guid>
		<description><![CDATA[Errors are unwanted, but is almost impossible to eliminate especially with a large application. We all know that we should minimize errors and that errors are bad, but to handle this there are three issues we need to be aware of: 1. Problem: When the user see an error in the application, the user becomes [...]]]></description>
			<content:encoded><![CDATA[<p>Errors are unwanted, but is almost impossible to eliminate especially with a large application.  We all know that we should minimize errors and that errors are bad, but to handle this there are three issues we need to be aware of:</p>
<p>1.<br />
<br /><em>Problem:</em> When the user see an error in the application, the user becomes unhappy and it results in a negative experience with the product. If this hapens often it will lead to the customer becoming unsatisfied and it addition it will hurt the brand image.<br />
<br /><em>Our solution:</em> When an error occurs a custom and a pleasant error page is displayed. It will alert the user that an error occurred and that it has been logged to a database. This gives the user confidence that the error will be fixed. It is also much better to view a relatively nice error page than a broken document with an ugly ASP error in the middle of the page.</p>
<p>2.<br />
<br /><em>Problem:</em> An error means a system bug. Most bugs are left unreported by user. For a developer it can be close to impossible to find and track all bugs.<br />
<br /><em>Our solution:</em> Using an error logging tool which logs all errors occurred to a database, developers have overview of when and where the error occurred, what the error message was, what input variables was given to the script and which user who executed the script. In most cases this will give the developer enough information to fix the error straight away or test the script and understand the cause of the error.</p>
<p>3.<br />
<br /><em>Problem:</em> When a user received an error when working with an important task or if the error repeats itself then the user calls customer service. Having worked in customer service earlier I know how difficult it is to get a clear overview of the user is doing and what the error is. When the developer gets the error report it is very hard to track and debug the error.<br />
<br /><em>Our solution:</em> When the user receives an error, the user is presented with an option to contact customer service through a form. This form automatically fills out the error reference. In addition the error reference number is displayed for the user so he/she can quote it when calling customer service. This results in the developer being able to pinpoint the error that occurred making the process much quicker and keeping the customer happy.</p>
<p><strong>So how do we do this in practice?</strong></p>
<p>1. Set up a custom error page in IIS. Create a page in your web-application, i.e. /system/error.asp. Have IIS execute this page when 500 and 500.100 error occurs. For more information <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasdj00/html/asp0084.asp">see this MSDN article</a>. The article covers how to implement a custom 404 page, but it&#8217;s the same with 500/500.100 pages, just select those from the list instead. I recommend that you set up a custom 404 page as well.</p>
<p>2. When that is done try to view a script with an error in your web-application. See it will redirect to the /system/error.asp page.</p>
<p>3. Next task is to create the error.asp page. First thing to do is design it with information that shall be displayed to the user. Then comes the scripting part:</p>
<p>Make sure you include response.clear at the top of the script. This is because when an error occurs IIS is doing a server.execute(&#8220;/system/error.asp&#8221;), thus all the contents from the script where the error occurred will be included unless the response is cleared.</p>
<p>then we get all the information about the error using the ASP error object:<br />

<pre name="code" class="vb">
	dim objErr, err_asp_desc, err_desc, err_no, err_src, err_line
	dim err_col, err_page, err_cat, err_asp_code, err_input, err_script
	set objErr = server.GetLastError()
	if objErr.Number <> 0 then
		err_asp_desc = objErr.ASPDescription
		err_desc = objErr.Description
		err_no = objErr.Number
		err_src = objErr.Source
		err_line = objErr.Line
		err_col = objErr.Column
		err_page = objErr.File
		err_cat = objErr.Category
		err_asp_code = objErr.ASPCode
		err_input = request.ServerVariables.Item("QUERY_STRING")
		err_script = request.ServerVariables.Item("SCRIPT_NAME")
	end if
	set objErr = Nothing
</pre>
<p>See there are scripts here. That is because when using an include file, the ASP error object will report the name of the include file if that is where the error occurred. But many times the script which holds the reference to the include file is the reason for the error, thus we need to get the script name as well.</p>
<p>The next task is to log this error to the database:</p>
<pre name="code" class="vb">
	dim c_db, sql, RefId, c_dbrs
	set c_db = server.CreateObject("ADODB.Connection")
	c_db.Open Application("ConnString")
	sql = "INSERT INTO Website_Error (ErrorNumber, ErrorDesc, Script, ErrorScript, QueryString, ErrorLine, ErrorColumn, ErrorCategory, ErrorSource, ASPError, ASPDescription, IP, UserId, ContactId) VALUES (" &#038; err_no &#038; ", '" &#038; err_desc &#038; "', '" &#038; err_script &#038; "', '" &#038; err_page &#038; "', '" &#038; err_input &#038; "', " &#038; err_line &#038; ", " &#038; err_col &#038; ", '" &#038; err_cat &#038; "', '" &#038; err_src &#038; "', '" &#038; err_asp_code &#038; "', '" &#038; err_asp_desc &#038; "', '" &#038; request.ServerVariables.Item("REMOTE_ADDR") &#038; "');"
	c_db.Execute(sql)
	sql = "SELECT @@Identity FROM Website_Error;"
	set c_dbrs = c_db.Execute(sql)
	RefId = c_dbrs.fields.item(0).value
	c_dbrs.close
	set c_dbrs = nothing
	c_db.Close
	set c_db = Nothing
</pre>
<p>The RefId is used to identify the error. This can be displayed to the user the user can quote this reference id when contacting customer service.</p>
<p>And there you have it &#8211; a custom error page with error logging!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/custom-error-page-on-iis-and-logging-27/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SMTP component</title>
		<link>http://blog.inspired.no/smtp-component-24</link>
		<comments>http://blog.inspired.no/smtp-component-24#comments</comments>
		<pubDate>Sat, 12 Jun 2004 12:43:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/smtp-component-24</guid>
		<description><![CDATA[We are currently looking for a SMTP component. Please leave a comment if you know any good compoents that can/is: - Stable, robust. Able to send a lot of email. - Mail merge. - Mass mailing. - Send embedded images (CID). - Queing. - Send email with both html and plain text in same email. [...]]]></description>
			<content:encoded><![CDATA[<p>We are currently looking for a SMTP component. Please leave a comment if you know any good compoents that can/is:</p>
<p>- Stable, robust. Able to send a lot of email.<br />
<br />- Mail merge.<br />
<br />- Mass mailing.<br />
<br />- Send embedded images (CID).<br />
<br />- Queing.<br />
<br />- Send email with both html and plain text in same email.</p>
<p>We are using ASP 3.0 (but looking into ASP.NET) and COM.</p>
<p>We are now using <a href="http://www.dynu.com/dynuemail.asp">DynuEmail</a>, but it lacks these features. So far my list includes: <a href="http://www.dimac.net">w3 Jmail</a> from Dimac,  <a href="http://fileup.softartisans.com/fileup-276.aspx">SoftArtisans SMTP Mail</a> and <a href="http://www.aspemail.com/">ASPEmail</a>. We used Jmail before but it was not stable (earlier version) and we did not receive support from Dimac, so i don&#8217;t think we will look much into that one.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/smtp-component-24/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to export XML from Microsoft SQL Server using ADO</title>
		<link>http://blog.inspired.no/how-to-export-xml-from-microsoft-sql-server-using-ado-21</link>
		<comments>http://blog.inspired.no/how-to-export-xml-from-microsoft-sql-server-using-ado-21#comments</comments>
		<pubDate>Wed, 09 Jun 2004 19:50:00 +0000</pubDate>
		<dc:creator>Espen Antonsen</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[ADO]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://inspired.goodcheapsleep.com/how-to-export-xml-from-microsoft-sql-server-using-ado-21</guid>
		<description><![CDATA[I previously wrote about exporting XML from Microsoft SQL Server and using it when generating reports from 24SevenOffice.com. Now i will show you how this is done. First we open a ADO connection and recordset just like we normally do. ' OPEN REPORT IN RECORDSET set c_db = server.CreateObject("ADODB.Connection") c_db.ConnectionString = Application.Contents.Item("ConnString") c_db.Open() Set ObjADORS [...]]]></description>
			<content:encoded><![CDATA[<p>I previously wrote about exporting XML from Microsoft SQL Server and using it when generating reports from 24SevenOffice.com. Now i will show you how this is done.</p>
<p>First we open a ADO connection and recordset just like we normally do.</p>
<pre name="code" class="vb">
' OPEN REPORT IN RECORDSET
set c_db = server.CreateObject("ADODB.Connection")
c_db.ConnectionString = Application.Contents.Item("ConnString")
c_db.Open()
Set ObjADORS = Server.CreateObject("ADODB.Recordset")
ObjADORS.Open sql, c_db,adOpenStatic,adLockReadOnly
set objStream = server.CreateObject("ADODB.Stream")
objStream.Charset = "ISO-8859-1"
' SAVE RECORDSET TO ADO STREAM AS XML
ObjADORS.Save objStream, adPersistXML
ObjADORS.Close
Set ObjADORS = Nothing
c_db.Close
set c_db = nothing
</pre>
<p>Look at the code above and youl will recognise all lines except for one &#8211; objADORS.Save objStream.adPersistXML. What i am doing is saving the ADO Recordset to ADO Stream, but not as ADO Recordset but in XML format (adPersistXML).</p>
<p>The next thing we need to do is get the XSLT and transform the XML using the XSLT:</p>
<pre name="code" class="vb">
' LOAD XSLT
set objXSLT = server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
objXSLT.createProcessingInstruction "xml", "version=""1.0"" encoding=""ISO-8859-1"""
objXSLT.async = false
objXSLT.load("file.xslt")

' LOAD THE XSLT TEMPLATE TRANSFORMER
set objXSLTTemplate = server.CreateObject("MSXML2.XSLTemplate.4.0")
objXSLTTemplate.stylesheet = objXSLT
set objXSLT = Nothing

' Load the XSLT processor
set xmlPro = objXSLTTemplate.createProcessor()
set objXSLTTemplate = Nothing

' USE THE ADO STREAM
xmlPro.input = objStream
objStream.Close
set objStream = Nothing
set objXMLDOM = Nothing

' Output to response
xmlPro.output = Response
' Transform XML using XSLT
xmlPro.transform
set xmlPRo = Nothing
</pre>
<p>The XSLT file looks like this:</p>
<p> </p>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"&gt;

&lt;xsl:output method="xml" media-type="text/xml" encoding="ISO-8859-1" /&gt;

&lt;xsl:template match="/"&gt;

&lt;xsl:element name="Entries"&gt;

&lt;xsl:for-each select="//rs:data/z:row"&gt;

&lt;xsl:element name="Entry"&gt;

&lt;xsl:attribute&amp;gt

&lt;xsl:value-of select="@DatabaseFieldName"/&gt;

&lt;/xsl:attribute&gt;

&lt;/xsl:element&gt;

&lt;/xsl:for-each&gt;

&lt;/xsl:element&gt;

&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
<p> </p>
<p>What you need is the //rs:data/z:row &#8211; this will list all the fields in the recordset. The XSLT transformer will then populate the final XSLT document with values from the XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.inspired.no/how-to-export-xml-from-microsoft-sql-server-using-ado-21/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
