<%
	'************************************************************************************
	'*																					*
	'*	MODIFICATION TO THIS SCRIPT OR ANY FILES INCLUDED WITH 							*
	'*		ONEWORLDSTORE IS DONE AT YOUR OWN RISK!										*
	'*	Product  : OneWorldStore														*
	'*	Version  : 9.0000																*
	'*	Modified : June 2004															*
	'*	Copyright:	Copyright (C) 2004 OneWorldStore.Com								*
	'*				Registration Number: 1024507										*
	'*				http://strategis.ic.gc.ca/											*
	'*																					*
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub DB_Connect()

		On Error Resume Next
		Set dbStoreConnection = CreateObject("ADODB.Connection")	' removed the "Server." because benchmarks show it faster w/o it
		If ( Err.Number <> 0 ) Then
			Call owMessage("Unable to instantiate the OneWorldStore database ADODB object: " & Err.Description, C_ERROR)
			Response.End
		Else
			dbStoreConnection.Open sDatabaseConnectionString
			dbStoreConnection.CursorLocation = adUseServer
			If ( Err.Number <> 0 ) Then
				Call owMessage("Unable to open the OneWorldStore database connection.<br><br>" & Err.Description, C_ERROR)
				Response.End
			Else
				Set dbStoreCommand					= Server.CreateObject("ADODB.Command")
				dbStoreCommand.CommandType			= adCmdText
				Set dbStoreCommand.ActiveConnection	= dbStoreConnection
			End If
		End If
		On Error Goto 0

	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	function DB_CloseConnection()

		If ( NOT IsObject(dbStoreConnection) ) Then
			dbStoreConnection.close
			set dbStoreConnection	= nothing
			SET dbStoreCommand		= Nothing
		End If

	end function
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub DB_getFromDatabase(sSQLText, rsStoreData, sScriptName) 

		On Error Resume Next
		sSQLText = Replace(sSQLText, "(NOLOCK)", "")
		sSQLText = Replace(sSQLText, "GetDate()", CONVERSION_FormatDate(Now(), "S"))
		rsStoreData.Open sSQLText, dbStoreConnection, adOpenKeyset, adLockReadOnly, adCmdText
		If ( Err.Number <> 0 ) Then
			If ( ( Err.Number <> 9 ) And ( Err.Number <> 5 ) And ( Err.Number <> 13 ) And ( Err.Number <> 94 ) And ( Err.Number<>424 ) And ( Err.Number <> 3265 ) ) Then
				Call DB_errorNote(Err.Description & "<br><BR><font size=-2>" & sSQLText & "<br></font>", sScriptName)
			End If
		End If
		On Error Goto 0
	
	End Sub
	'************************************************************************************


	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	sub DB_updateDatabase(sSQLText) 

'		On Error Resume Next
		sSQLText = Replace(sSQLText, "GetDate()", "#" & CONVERSION_FormatDate(Now(), "L") & "#")
		dbStoreConnection.Execute sSQLText
		If ( Err.Number <> 0 ) Then
			If ( ( Err.Number <> 9 ) And ( Err.Number <> 5 ) And ( Err.Number <> 13 ) And ( Err.Number <> 94 ) And ( Err.Number<>424 ) And ( Err.Number <> 3265 ) ) Then
				Call DB_errorNote(Err.Description & "<br><BR><font size=-2>" & sSQLText & "<br></font>", sScriptName)
			End If
		End If
		On Error Goto 0

	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	sub DB_closeRecordset(rsObject)

		On Error Resume Next
		rsObject.Close
		If ( Err.Number <> 0 ) Then
			If ( ( Err.Number <> 9 ) And ( Err.Number <> 5 ) And ( Err.Number <> 13 ) And ( Err.Number <> 94 ) And ( Err.Number<>424 ) And ( Err.Number <> 3265 ) ) Then
				Call DB_errorNote(Err.Description, sScriptName)
			End If
		End If
		On Error Goto 0

	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	sub DB_errorNote(sError, sScriptName)

		' LEAVE THIS OUT OF THE LANGUAGE DATABASE. If we have to look up text in the database
		'	and the database error was a READ error, we are now trapped in an infinite loop
		
		If ( sScriptName <> "" ) Then
			sScriptName = "<font size=-2><i>Error occurred within the " & sScriptName & " script.</i></font>"
		End If
		%>
		<table><tr><td>
		Database operations error:<bR><br>
		<code><%=sError%></code>
		<%=sScriptName%>
		<br><br>
		<b>Common solutions</b>
		<ol>
			<li>Check that you haven't change default database path and name.
			<li>Check that your web server has Access 97 or 2000 ODBC installed.
			<li>Check that you have read, modify and delete permissions over database folder and database file.
			<li>Open your database with Access program and select Repair Database option.
			<li>Select other connection method like other connection string or DSN.
		</ol>
		</td></tr></table>
		<%
		'Response.End

	End Sub
	'************************************************************************************
%>