sql query error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
'============================================================


.



Relevant Pages

  • Re: Workday Function - Holidays
    ... dhAddWorkDaysA([T Const Schedules]!PourFootings,dhAddWorkDaysA([T Const ... that may well make the SQL too long ... Doug Steele, Microsoft Access MVP ... (no private e-mails, please) ...
    (microsoft.public.access.gettingstarted)
  • User Infos per DB ändern im AD
    ... Danach komme die Felder die ich ändern ... Const SQL = "SELECT * FROM domain_users" ... Set ws_UTIL = CreateObject ... ' --- Verbindung herstellen, SQL ausführen ...
    (microsoft.public.de.german.scripting.wsh)
  • Re: Idea for Borland
    ... I frequently write SQL in an analysis tool and paste it ... > into code as a const. ... Using macro record and playback lets me stick in ...
    (borland.public.delphi.non-technical)
  • Re: Item cannot be found in the collection corresponding to the requested name or ordinal.
    ... conn.execute SQL ... I'm a little hesitant to reply, never having used Oracle, but in SQL Server, ... const adParamReturnValue=4 ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)
  • vbs script to sql db help
    ... I am trying to combine two scripts into one and document what each step ... Find Disk Free Space in all the listed servers in a table ... Const adLockOptimistic = 3 ... Dim i, SQL ...
    (microsoft.public.scripting.vbscript)