Helper methods for running Access generated reports from ASP.NET

I am using Access reports exported as xml/xsl and  show them in ASP.NET as it is described in Access: Your New .NET Report Writer by Danny J. Lesandrini.


There are a few methods then can be useful for others who want to use the same technicque.


Note that the original article uses DataSetName = “dataRoot” which causes problems for generated xsl files, because XML is case-sensitive and MS access generate XML with  “dataroot“ element-all low case.


‘TODO create COM wrapper and use early binding 

   

‘ domDoc = Server.CreateObject(“MSXML.DOMDocument”)


    ‘sXslPath -absolute XSL file path


    Public Shared Function DOMDocumentTransform(ByVal domDoc As Object, ByVal sXslPath As String) As String


          Instead of using the XML Web Control we can use traditional VB Script solution.


        Dim objStyle As Object


        Dim Server As HttpServerUtility = HttpContext.Current.Server


        objStyle = Server.CreateObject(“MSXML.DOMDocument”)


        objStyle.load(sXslPath)


        Dim strOut As String


        strOut = domDoc.transformNode(objStyle)


        Return strOut


    End Function


    ‘TODO create COM wrapper and use early binding to return “MSXML.DOMDocument”)


    Public Shared Function DataSetToDOMDocument(ByVal ds As DataSet) As Object


        Dim domDoc As Object ‘TODO create COM wrapper and use early binding


        domDoc = HttpContext.Current.Server.CreateObject(“MSXML.DOMDocument”)


        domDoc.loadXML(ds.GetXml)


        Return domDoc


    End Function


    ‘TableName must be exactly the same as in Access Generated xsl file, case sensitive!


    Public Shared Function LoadDataSet(ByVal connString As String, ByVal sSQL As String, ByVal TableName As String) As DataSet


        ‘ load the data and write it to our xml file.


        Dim ds As DataSet


        ds = SqlHelper.ExecuteDataset(connString, CommandType.Text, sSQL)


        ds.DataSetName = “dataroot” ‘ESSENTIAL all low case


        ds.Tables(0).TableName = TableName ‘XSLT is case sencitive


        Debug.WriteLine(ds.GetXml)


        Return ds


    End Function

Configuration class for Session Data Management Tool

I’ve posted a code of  Configuration class for  Session Data Management Tool created by Xiangyang Liu to store data between different threads in ASP.NET asyncronous application.


The source code of the tool has SessionService web site where configuration is done in global.asax.


To make it easier to incorporate it into existing  ASP.Net web application, it was moved to a separate class. The changes also were done to store trace and data folders in Temp directory, which is easier for deployment.

Configuration class for Session Data Management Tool

I am using Session Data Management Tool created by Xiangyang Liu to store data between different threads in ASP.NET asyncronous application.

The source code of the tool has SessionService web site where configuration is done in global.asax.

To make it easier to incorporate it into existing  ASP.Net web application, it was moved to a separate class. The changes also were done to store trace and data folders in Temp directory, which is easier for deployment.

Option Strict On

Option Explicit On

 

Imports Microsoft.VisualBasic.ControlChars

Imports System.Threading

Imports System.Runtime.Serialization

Imports System.Runtime.Serialization.Formatters.Binary

Imports System.IO

Imports Tools.TraceUtility

Imports System.Configuration ‘mnf 21/9/2005

‘Imports System.Web ‘mnf 21/9/2005 Added reference

 

Public Class SessionManagerStartEnd

    ‘Ideally it will be good to pass HttpSessionState.Timeout to make it the same as  SessionManager.Timeout

    ‘However HttpSessionState.Timeout is known on Session_Start, not Application_Start event

    ‘TODO extract HttpSessionState.Timeout from Web,config in  Application_Start

    Public Shared Sub ApplicationStart(ByVal VirtDir As String) ‘ByVal SessionTimeout As Integer) ‘ByVal Server As HttpServerUtility)

        Dim sRootFolder As String ‘= Server.MapPath(“.”) + “..”

        Dim sTraceFilePrefix As String = ConfigurationSettings.AppSettings.Get(“TraceFilePrefix”)

        If sTraceFilePrefix Is Nothing OrElse sTraceFilePrefix = “” Then

            sTraceFilePrefix = “LogSessionService”

        End If

        If sTraceFilePrefix.IndexOf(“:”) Then

            sTraceFilePrefix = GetPathInTempFolder(VirtDir, sTraceFilePrefix) ‘sRootFolder + sTraceFilePrefix

        End If

        SetTraceFilePrefix(sTraceFilePrefix)

        Dim sTraceLevel As String = ConfigurationSettings.AppSettings.Get(“TraceLevel”)

        If sTraceLevel Is Nothing OrElse sTraceLevel = “” Then

            sTraceLevel = “40”

        End If

        SetTraceLevel(CInt(sTraceLevel))

        Dim sTraceCleanup As String = ConfigurationSettings.AppSettings.Get(“TraceCleanup”)

        If sTraceCleanup Is Nothing OrElse sTraceCleanup = “” Then

            sTraceCleanup = “7”

        End If

        SetCleanupSchedule(CInt(sTraceCleanup))

        WriteTrace(30, “SessionService started”)

        Dim mgr As SessionManager = New SessionManager

        Dim sFilePath As String = ConfigurationSettings.AppSettings.Get(“SessionDataFile”)

        If sFilePath Is Nothing OrElse sFilePath = “” Then

            sFilePath = “DataSessionDataFile”

        End If

        If sFilePath.IndexOf(“:”) Then

            sFilePath = GetPathInTempFolder(VirtDir, sFilePath) ‘ sRootFolder + sFilePath

        End If

        mgr.SetSessionDataFile(sFilePath)

        Dim sTimeout As String = ConfigurationSettings.AppSettings.Get(“Timeout”)

        If Not sTimeout Is Nothing AndAlso sTimeout “” Then

            mgr.SetTimeout(CInt(sTimeout))

        End If

        ‘If SessionTimeout > 0 Then

            mgr.SetTimeout(SessionTimeout)

        ‘End If

        mgr.OnStart()

    End Sub

    Public Shared Function GetPathInTempFolder(ByVal VirtDir As String, ByVal RelativeFolderName As String) As String

        Dim sTempFolderName As String = Path.GetTempPath()         Environment.GetEnvironmentVariable(“TEMP”)

        sTempFolderName = Path.Combine(sTempFolderName, VirtDir & “SessionTools”)

        Dim pathTarget As String = Path.Combine(sTempFolderName, RelativeFolderName)

        Dim sTargetDir As String = Path.GetDirectoryName(pathTarget)

        If (Not Directory.Exists(sTargetDir)) Then

            Directory.CreateDirectory(sTargetDir)

        End If

        Return pathTarget

    End Function

 

    Public Shared Sub ApplicationEnd()

        Dim mgr As SessionLib.SessionManager = New SessionLib.SessionManager

        mgr.OnStop()

        WriteTrace(30, “SessionService ended”)

    End Sub

 

 

End Class