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
%>