Tuesday, July 30, 2013

Classic ASP DB Conn Cheat

For those time when you gotta go back but don't want to make it too bad...

Scenario: Classic ASP ap (perhaps mixed with .net) that has BO layer in ActiveX dll's (VB, of all things). You want perform some follow-up work after the dll method has run.

We could parse web.config for the connection string and then reformat for ADO ... or we could just use a separate connection string and store it in an include file:


' Joe Kelly
' 2013.07.30
' Classic.inc
' Changed to use ../Include/Classic.inc so as to have one place to manage
' connection strings for Classic ASP
' Page Admin_Imp_Expense.asp, part of the "Monthly Expense Detail" process
' uses this file 

Dim connPortal
connPortal = "Provider=SQLNCLI10;Server=TESTSQL;Database=TESTPortal;Uid=TESTUser;Pwd=TESTPw;"


And then to use it ...

    Dim conn, cmd, result 

    Set conn = Server.CreateObject("ADODB.Connection")
    Set cmd = Server.CreateObject("ADODB.Command")
    conn.ConnectionString = connPortal
    cmd.ActiveConnection = conn
    cmd.CommandText = "EXEC dbo.someProc; "
    Set result = cmd.Execute
    If result.EOF = False Then
        While result.EOF = False
            Response.Write ("")
            Response.Write (result.Fields("DEDFYXXRecords"))
    End If
    Set conn = Nothing
    Set cmd = Nothing

No comments: