Compile function SQL_Probe_Services(@Service, @Params)
#pragma precomp SRP_PreCompiler
$insert APP_INSERTS
$insert SERVICE_SETUP
$insert REVDOTNETEQUATES

Declare subroutine SQL_Services, Logging_Services, Set_Status
Declare function   SQL_Services, Logging_Services, Environment_Services, Database_Services

LogPath      = Environment_Services('GetApplicationRootPath') : '\LogFiles\SQL_Probe'
LogDate      = Oconv(Date(), 'D4/')
LogTime      = Oconv(Time(), 'MTS')
LogFileName  = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' SQL Probe1 Log.csv'
Headers      = 'Log DTM':@FM:'Notes'
objProbe1Log = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, COMMA$, Headers, '', False$, False$)
LogFileName  = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' SQL Probe2 Log.csv'
objProbe2Log = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, COMMA$, Headers, '', False$, False$)
LoggingDTM   = LogDate : ' ' : LogTime  

GoToService

Return Response or ""

//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------

Service Probe1()

    hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
    Lock hSysLists, ServiceKeyID then
        objConnection = Sql_Services('GetConnectionObject', 'IQSDMS1')
        If Error_Services('NoError') then
            Query     = 'SELECT [Probe_Key] FROM [G4Wafers_01].[dbo].[Probe1]'
            Key       = SQL_Services('ExecuteQuery', objConnection, Query, True$, 1)
            If ((Key EQ '') or (Key EQ 0)) then
                LogData    = ''
                LogData<1> = LoggingDTM
                LogData<2> = 'Value of ':Key:' returned when an integer greater than 0 was expected.'
                Logging_Services('AppendLog', objProbe1Log, LogData, @RM, @FM)
            end else
                NewKey        = Key + 1
                Statement     = 'UPDATE [G4Wafers_01].[dbo].[Probe1] SET [Probe_Key] = ':NewKey:' WHERE [Probe_Key] = ':Key
                SQL_Services('ExecuteQuery', objConnection, Statement, 0, 1)
                Query   = 'SELECT [Probe_Key] FROM [G4Wafers_01].[dbo].[Probe1]'
                Key     = SQL_Services('ExecuteQuery', objConnection, Query, True$, 1)
                If Key NE NewKey then
                    LogData    = ''
                    LogData<1> = LoggingDTM
                    LogData<2> = 'Value of ':Key:' returned when ':NewKey: ' was expected.'
                    Logging_Services('AppendLog', objProbe1Log, LogData, @RM, @FM)
                end
            end
            SQL_Services('DestroyConnectionObject', objConnection)
        end
        Unlock hSysLists, ServiceKeyID else Null
    end
    
End Service


Service Probe2()

    hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
    Lock hSysLists, ServiceKeyID then
        
        DotNetHandle        = StartDotNet("","4.0")
        DotNetDir           = CheckDotNet('4.0'):'\'
        SqlClientDLLPath    = DotNetDir:'System.Data.dll'
        ConnectionString    = 'Password=mesa@1234@IQSDMS1!0987;Persist Security Info=True;User ID=IQSDMS1;Initial Catalog=G4Wafers_01;Data Source=messv01ec.ec.local\PROD1,53959'
        //Specify the DLL
        rv = Set_Property.NET(DotNetHandle, "AssemblyName", SqlClientDLLPath)
        //Define the classes
        SqlConnectionObj = Create_Class.NET(DotNetHandle, "System.Data.SqlClient.SqlConnection", 0, ConnectionString, 'System.String')
        IF Not(Get_Status(errCode)) THEN
            Set_Status(0)
            rv = Send_Message.Net(SqlConnectionObj, "Open")
            IF Not(Get_Status(errCode)) THEN
                ConnectionState = Get_Property.Net(SqlConnectionObj, "State")
                If ConnectionState EQ 'Open' then
                    SQLStatement  = "select [Probe_Key] from [G4Wafers_01].[dbo].[Probe2]"
                    Params        = SQLStatement:@FM:SqlConnectionObj
                    ParamTypes    = 'System.String':@FM:'RevDotNet'
                    Set_Status(0)
                    SqlCommandObj = Create_Class.NET(DotNetHandle, "System.Data.SqlClient.SqlCommand", 0, Params, ParamTypes)
                    If Not(Get_Status(errCode)) then
                        Set_Status(0)
                        ProbeKey = Send_Message.Net(SqlCommandObj, "ExecuteScalar")
                        If Not(Get_Status(errCode)) then
                            If ( (ProbeKey NE 0) and (ProbeKey NE '') ) then
                                NewProbeKey = ProbeKey + 1
                                SQLStatement = 'update [G4Wafers_01].[dbo].[Probe2] set [Probe_Key] = ':NewProbeKey:' where [Probe_Key] = ':ProbeKey
                                Set_Status(0)
                                rv = Set_Property.NET(SqlCommandObj, "CommandText", SQLStatement)
                                If Not(Get_Status(errCode)) then
                                    Set_Status(0)
                                    rv = Send_Message.Net(SqlCommandObj, "ExecuteNonQuery")
                                    If Not(Get_Status(errCode)) then
                                        // Verify Probe Key was updated
                                        SQLStatement = "select [Probe_Key] from [G4Wafers_01].[dbo].[Probe2]"
                                        Set_Status(0)
                                        rv = Set_Property.NET(SqlCommandObj, "CommandText", SQLStatement)
                                        If Not(Get_Status(errCode)) then
                                            Set_Status(0)
                                            VerifyProbeKey = Send_Message.Net(SqlCommandObj, "ExecuteScalar")
                                            If Not(Get_Status(errCode)) then
                                                If VerifyProbeKey NE NewProbeKey then
                                                    LogData    = ''
                                                    LogData<1> = LoggingDTM
                                                    LogData<2> = 'Value of ':VerifyProbeKey:' returned when ':NewProbeKey: ' was expected.'
                                                    Logging_Services('AppendLog', objProbe2Log, LogData, @RM, @FM)
                                                end
                                            end
                                        end
                                    end
                                end
                            end else
                                LogData    = ''
                                LogData<1> = LoggingDTM
                                LogData<2> = 'Value of ':ProbeKey:' returned when an integer greater than 0 was expected.'
                                Logging_Services('AppendLog', objProbe2Log, LogData, @RM, @FM)
                            end
                        end
                    end
                    rv = Send_Message.Net(SqlConnectionObj, 'Close')
                    ConnectionState = Get_Property.Net(SqlConnectionObj, "State")
                end
            end
        end
        Free_Class.Net(SqlConnectionObj)
        Unlock hSysLists, ServiceKeyID else Null
    end
    
End Service


Service AppProbe1()

    hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
    Lock hSysLists, ServiceKeyID then
        Query = 'SELECT [Probe_Key] FROM [G4Wafers_01].[dbo].[Probe1]'
        Key   = SQL_Services('PostSQLRequest', 'IQSDMS1', Query)
        If ((Key EQ '') or (Key EQ 0)) then
            LogData    = ''
            LogData<1> = LoggingDTM
            LogData<2> = 'Value of ':Key:' returned when an integer greater than 0 was expected.'
            Logging_Services('AppendLog', objProbe1Log, LogData, @RM, @FM)
        end else
            NewKey        = Key + 1
            Statement     = 'UPDATE [G4Wafers_01].[dbo].[Probe1] SET [Probe_Key] = ':NewKey:' WHERE [Probe_Key] = ':Key
            SQL_Services('PostSQLRequest', 'IQSDMS1', Statement)
            Query   = 'SELECT [Probe_Key] FROM [G4Wafers_01].[dbo].[Probe1]'
            Key   = SQL_Services('PostSQLRequest', 'IQSDMS1', Query)
            If Key NE NewKey then
                LogData    = ''
                LogData<1> = LoggingDTM
                LogData<2> = 'Value of ':Key:' returned when ':NewKey: ' was expected.'
                Logging_Services('AppendLog', objProbe1Log, LogData, @RM, @FM)
            end
        end
        Unlock hSysLists, ServiceKeyID else Null
    end
    
End Service
