<% ' Constants used for DBMS Const DBMS_ACCESS = "Access" ' Source is an Access database Const DBMS_SQL = "SqlServer" ' Source is a database in a SQL Server Const DBMS_DSN = "OdbcDsn" ' Source is fully described by a ODBC DSN Dim strConn, conDB, rsData, sSQL Dim sDBSource, sDBName, sDBUser, sDBPwd, sDBMS, bDBExtraPath ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''' DATABASE SETUP '''''''''''''''''''''''''''''''' ' sDBSource - Holds SQL Server IP address or Access MDB file path. ' ' sDBName - Database name for SQL Server. ' ' sDBUser - Database user. ' ' sDBPwd - Database pwd. ' ' sDBMS - Database management system. Use DBMS_ constants. ' ' ' ' Typical setup for a SQL Server connection: ' ' sDBSource = "draftsql.worldsites.net" ' ' sDBName = "db_infolinksa_com" ' ' sDBUser = "dbm_infolinksa_com" ' ' sDBPwd = "secret" ' ' sDBMS = DBMS_SQL ' ' ' ' Typical setup for an Access connection: ' ' sDBSource = "admin/data.mdb" ' ' sDBUser = "admin" ' ' sDBPwd = "secret" ' ' sDBMS = DMBS_ACCESS ' ' ' ' Typical setup for a database that uses a DSN: ' ' sDBSource = "DSN_SAMPLE" ' ' sDBUser = "admin" ' ' sDBPwd = "secret" ' ' sDBMS = DMBS_DSN ' ' ' ' Use one of the previos modes and the code will do the rest. ' ' ' ' *IMPORTANT NOTE: There is an optional variable that can be used when sDBMS' ' is DBMS_ACCESS: bDBExtraPath. When this variable is set ' ' to True, the code expects that YOU define sDBExtraPath. ' ' Use sDBExtraPath to prepend path information to the ' ' sDBSource variable. ' ' ' ' Example: ' ' ' ' Dim sDBExtraPath ' ' sDBExtraPath = "../" ' ' ' ' Leave sDBSource as if the database is going to be used ' ' from the web site root. ' ' ' ' sDBSource = "admin/data.mdb" ' ' ' ' The code will combine them like this when bDBExtraPath ' ' is set to True: ' ' ' ' sDBSource = sDBExtraPath + sDBSource ' ' ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' sDBSource = "misc/sbiia.mdb" sDBMS = DBMS_ACCESS bDBExtraPath = True '--**----**----**----**----**----**----**----**----**----**----**----**----*' '--**----**----** PLEASE DON'T MODIFY THE FOLLOWING CODE *----**----**----*' '--**----**----**----**----**----**----**----**----**----**----**----**----*' ' ADO Most used constants Const adOpenForwardOnly = 0 Const adOpenKeyset = 1 Const adOpenDynamic = 2 Const adOpenStatic = 3 Const adLockReadOnly = 1 Const adLockPessimistic = 2 Const adLockOptimistic = 3 Const adCmdText = 1 Const adCmdTable = 2 Const adCmdStoredProc = 3 Dim sConTemp, objConFso Select Case sDBMS Case DBMS_SQL ' Build connection string strConn = "Driver={SQL Server};Server=" & sDBSource & ";UID=" & sDBUser & ";PWD=" & sDBPwd & ";Database=" & sDBName Case DBMS_ACCESS ' Get real path for the MDB file If bDBExtraPath Then sDBSource = sDBExtraPath + sDBSource sConTemp = Server.MapPath(sDBSource) ' Check if file exists Set objConFso = Server.CreateObject("Scripting.FileSystemObject") Die Not objConFso.FileExists(sConTemp), "MDB file ('" & sDBSource & "') does not exist. This file may be misconfigured. " ' Build connection string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sConTemp Case DBMS_DSN ' Build connection string strConn = sDBSource Case Else Die True, "No DBMS specified. Please edit site connection settings." End Select ' Default database objects Set conDB = Server.CreateObject("ADODB.Connection") On Error Resume Next Err.Clear conDB.Open strConn, sDBUser, sDBPwd Die Err.Number <> 0, "Cannot connect to database. ADO returns the following error: " & Hex(Err.Number) & ": " & Err.Description & "" On Error Goto 0 Set rsData = Server.CreateObject("ADODB.Recordset") Set rsData.ActiveConnection = conDB Function IsRSEmpty(ByRef rs) IsRSEmpty = rs.BOF And rs.EOF End Function Function Die(bDieCondition, sMessage) If bDieCondition Then If Response.Buffer Then Response.Clear Response.Write sMessage If Response.Buffer Then Response.Flush Response.End End If End Function Function ToDB(varValue) If Len(varValue) = 0 Then ToDB = Null Else ToDB = varValue End Function Function ToSQL(varValue) ToSQL = Replace(varValue, "'", "''") End Function Function IIf(cond, valTrue, valFalse) If cond Then IIf = valTrue Else IIf = valFalse End Function Function NullDoubleCheckWithOutput(oData1, oData2, sOutput1, sOutput2, sOutputNull) NullDoubleCheckWithOutput = sOutputNull If Not IsNull(oData1) Then If Len(oData1) > 0 Then NullDoubleCheckWithOutput = sOutput1 End If End If If Len(NullDoubleCheckWithOutput) = 0 Then If Not IsNull(oData2) Then If Len(oData2) > 0 Then NullDoubleCheckWithOutput = sOutput2 End If End If End If End Function Function GetRelatedValue(sSQL) Dim rsTemp Set rsTemp = conDB.Execute(sSQL) If Not IsRSEmpty(rsTemp) Then GetRelatedValue = rsTemp(0) If IsNull(GetRelatedValue) Then GetRelatedValue = "" End If rsTemp.Close Set rsTemp = Nothing End Function Function CreateRS() Dim rsNew Set rsNew = Server.CreateObject("ADODB.Recordset") Set rsNew.ActiveConnection = conDB Set CreateRS = rsNew End Function %>