We switch database vendors without changing every .asp
page of a web by calling a custom VBScript function. The
function takes the specific database name as its single
arguement and returns a complete OLE connection string for
that database. Thus, a single file (the function) only
needs editing to switch from one database (eg SQL Server)
to another (eg: ORACLE).

Other VBScript custom functions in the web also require
database connection(s). How do they use the same function
to create their connection string(s)?

Example:

In the .asp we have ...


<!-- #include file = ../functions/dboledb.inc -->
<%
'Script:
Dim cnnActive
Dim strOLEDB
...
Set cnnActive = Server.CreateObject ("ADODB.Connection")
strOLEDB = OLEDBString("Active")
cnnActive.Open strOLEDB
...
%>


Here's the function:

<%

Function OLEDBString(strDB)

'>>>
'>>> Create the OLEDB connection string for the customer
database
'>>> Here, use the Microsoft Access JET OLEDB v4
'>>>

'Create the link with the [strDB] database
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;"
OLEDBString = OLEDBString & "Data
Source=C:\InetPub\wwwroot\VManager\databases\"
OLEDBString = OLEDBString & strDB & ".mdb;"
OLEDBString = OLEDBString & "User ID=admin; Password=;"

End Function

%>

Re: Functions calling Functions by MikeB

MikeB
Mon Oct 20 16:22:04 CDT 2003

It's been awhile since I did this, but it's been working for a couple of years. The difference in
my method is I return a Connection Object to the Asp page from the Include file. The Function
MakeCN could be altered to pass in a string value for the database type and you could use a Select
Case to get the appropriate Connection Object:

Function MakeCN()
Dim DbPath
DbPath = Server.Mappath(".")
If isObject(MakeCN) = False then
Set MakeCN = Server.CreateObject("ADODB.Connection")
With MakeCN
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionTimeout = 15
.CommandTimeout = 10
.Mode = adModeReadWrite
.Open DbPath & "\fpdb\SomeAccessDb.mdb", "admin", ""
End With
Else
if MakeCN.State = adStateClosed then
MakeCN.Open DbPath & "\SomeAccessDb.mdb", "admin", ""
end if
End If
End Function

"GrahamC" <grahamc@inetix.com> wrote in message news:042101c39741$7514c630$a101280a@phx.gbl...
> We switch database vendors without changing every .asp
> page of a web by calling a custom VBScript function. The
> function takes the specific database name as its single
> arguement and returns a complete OLE connection string for
> that database. Thus, a single file (the function) only
> needs editing to switch from one database (eg SQL Server)
> to another (eg: ORACLE).
>
> Other VBScript custom functions in the web also require
> database connection(s). How do they use the same function
> to create their connection string(s)?
>
> Example:
>
> In the .asp we have ...
>
>
> <!-- #include file = ../functions/dboledb.inc -->
> <%
> 'Script:
> Dim cnnActive
> Dim strOLEDB
> ...
> Set cnnActive = Server.CreateObject ("ADODB.Connection")
> strOLEDB = OLEDBString("Active")
> cnnActive.Open strOLEDB
> ...
> %>
>
>
> Here's the function:
>
> <%
>
> Function OLEDBString(strDB)
>
> '>>>
> '>>> Create the OLEDB connection string for the customer
> database
> '>>> Here, use the Microsoft Access JET OLEDB v4
> '>>>
>
> 'Create the link with the [strDB] database
> OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;"
> OLEDBString = OLEDBString & "Data
> Source=C:\InetPub\wwwroot\VManager\databases\"
> OLEDBString = OLEDBString & strDB & ".mdb;"
> OLEDBString = OLEDBString & "User ID=admin; Password=;"
>
> End Function
>
> %>