The code is below. The issue I am having is if I query the database for a
specific table and if it's not created I throw the following error:

Microsoft OLE DB Provider for SQL Server: Invalid object name 'IB_Flags'

I tried catching error using err object but it does not appear to catch the
description or error number.

How can either check for this error or check to see if the table even
exists?





Const Source = "BackOfficeMenu"
CONST MSIF_LOGS_DIR = "C:\MSIF\LOGS\"
CONST INSTALL_DEBUG_LOG = "IBDADS.log"

' File system CONSTants
CONST ForReading = 1, ForWriting = 2, ForAppending = 8

'Alert categories
CONST C = "Critical"
CONST I = "Information"
CONST W = "Warning"

Set objFSO = CreateObject("Scripting.FileSystemObject")

' CREATE LOG
If objFSO.FileExists(MSIF_LOGS_DIR & INSTALL_DEBUG_LOG) Then
Set objFile = objFSO.OpenTextFile(MSIF_LOGS_DIR & INSTALL_DEBUG_LOG,
ForAppending)
Else
Set objFile = objFSO.CreateTextFile(MSIF_LOGS_DIR & INSTALL_DEBUG_LOG,
true)
End If

'SQL connection string
strCon = "Provider=sqloledb;Data Source=.;Initial Catalog=backoffice;User
Id=sa;Password=password"

' Create the required ADO objects.
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
' Open the connection.
conn.Open strCon


SqlStatment()
LogIt I, Source, "SQL query " & SqlStatment

Set rs=conn.Execute(SqlStatment,1)
strReturn=rs.eof

LogIt I, Source, "ACES is " & strReturn


'Logic to copy menu over for a ACES enabled/disabled store
If strReturn = 0 Then
NewMenu("Enabled")
Else
NewMenu("Disabled")
End If


'Cleanup
conn.Close
Set conn = Nothing
Set rs = Nothing
Set f1 = Nothing
Set f2 = Nothing

Function SqlStatment ()
'*********************************************************
' Name: SqlStatement
' Purpose: build SQL statement
' Returns: strSQL
'*********************************************************

strSQL = "Select Brand, Name, enabledate, disabledate from IB_Flags "
'strSQL = strSQL & "where Brand = 'BBW'"
strSQL = strSQL & "where Name = 'ACES'"
strSQL = strSQL & "and (enabledate <= getDate()) "
strSQL = strSQL & "and ((disabledate is null) or (disabledate >=
getDate())or (enabledate <> disabledate))"

SqlStatment=strSql ' return SQL string to main

End Function


Function NewMenu (blnValue)
'*********************************************************
' Name: NewMenu
' Purpose: copy menu.xml to c:\webapps\menu if a newer nenu exists
' Returns:
'*********************************************************
Const OverwriteExisting = True
Const MENU_HOLDING_DIR = "C:\Webapps\menu\Holding\"
Const MENU_DESTINATION_DIR = "C:\Webapps\menu\"
Const MENU_HOLDING_ACESENABLED = "menu-ACES.xml"
Const MENU_HOLDING_ACESDISABLED = "menu-nonACES.xml"
Const MENU_NAME = "menu.xml"

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set f2 = objFSO.GetFile(MENU_HOLDING_DIR & "menu-NonAces.xml")

If blnValue = "Enabled" Then

If objFSO.FileExists(MENU_HOLDING_DIR & MENU_HOLDING_ACESENABLED) Then
Set f1 = objFSO.GetFile(MENU_HOLDING_DIR & MENU_HOLDING_ACESENABLED)
Else
LogIt W, Source, "Exiting script, " & MENU_HOLDING_DIR &
MENU_HOLDING_ACESENABLED & " does not exist"
WScript.Quit
End If


If objFSO.FileExists(MENU_DESTINATION_DIR & MENU_NAME) Then
Set f2 = objFSO.GetFile(MENU_DESTINATION_DIR & MENU_NAME)
Else
LogIt W, Source, "Exiting script, " & MENU_DESTINATION_DIR & MENU_NAME
& " does not exist"
WScript.Quit
End If

If f1.size <> f2.size OR f1.DateLastModified <> f1.DateLastModified
Then
LogIt I, Source, "ACES enabled, files are different"
objFSO.CopyFile MENU_HOLDING_DIR & MENU_HOLDING_ACESENABLED ,
MENU_DESTINATION_DIR & MENU_NAME, OverwriteExisting
End If

Else

If objFSO.FileExists(MENU_HOLDING_DIR & MENU_HOLDING_ACESDISABLED) Then
Set f1 = objFSO.GetFile(MENU_HOLDING_DIR & MENU_HOLDING_ACESDISABLED)
Else
LogIt W, Source, "Exiting script, " & MENU_HOLDING_DIR &
MENU_HOLDING_ACESDISABLED & " does not exist"
WScript.Quit
End If

If objFSO.FileExists(MENU_DESTINATION_DIR & MENU_NAME) Then
Set f2 = objFSO.GetFile(MENU_DESTINATION_DIR & MENU_NAME)
Else
LogIt I, Source, "Exiting script, " & MENU_DESTINATION_DIR & MENU_NAME
& " does not exist"
WScript.Quit
End If


If f1.size <> f2.size OR f1.DateLastModified <> f1.DateLastModified
Then
LogIt I, Source, "ACES disabled, files are different"
objFSO.CopyFile MENU_HOLDING_DIR & MENU_HOLDING_ACESDISABLED ,
MENU_DESTINATION_DIR & MENU_NAME, OverwriteExisting
End If

End If

End Function

'============================================================
sub LogIt(byVal strSeverity, strSource, strMessage)
dim tempMsg
tempMsg = Now & "|" & strSeverity & "|" & strSource & "|" & strMessage
Wscript.echo tempMsg
objFile.writeline tempMsg
end sub
'============================================================

Re: sql query error by Bob

Bob
Thu May 26 12:31:03 CDT 2005

Big D wrote:
> The code is below. The issue I am having is if I query the database
> for a specific table and if it's not created I throw the following
> error:
>
> Microsoft OLE DB Provider for SQL Server: Invalid object name
> 'IB_Flags'
>
> I tried catching error using err object but it does not appear to
> catch the description or error number.

http://www.aspfaq.com/show.asp?id=2458

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.