CreateObject in VB Script fails with no error message - createobject

I have deployed a 64-bit COM+ application and while trying to create an instance of it via script, it fails with no error message and a negative error code (-2146233036).
The script:
dim myObj on error resume next set myObj = CreateObject("TestApp.1")
if (Err.number <> 0)
then MsgBox Err.Number & " " & Err.Message
end if
if (myObj is nothing)
then MsgBox "Null" else MsgBox "Not Null"
end if
Essentially I was trying to troubleshoot of why CoCreateInstanceEx was failing for the same. How do I find out what happens behind the scene? At which step is it failing?

Related

FindItems() does not work in first run but works in the second run

I am trying to fetch latest mail from my Outlook Exchange server mailbox using PowerShell. I have seen that the most common solution is to do a FindItems() method on the inbox object. However, I find that that running the code first time throws error stating
Exception calling "FindItems" with "1" argument(s): "The request failed.
When I run it once again, the script completes successfully returning the last mail from my mailbox. In order to make it more clear, I wrote a script to execute the FindItems() method to execute twice in a while loop as shown below:
# bind to the Inbox folder of the target mailbox
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
echo outsideWhile
$i = 0
while ($i -ne 2) {
echo insideWhileBefore
$inbox.FindItems(1)
echo insideWhileAfter
$i += 1
}
The first execution of $inbox.FindItems(1) fails but the second execution goes through fine returning the desired results.
The result output is as shown below
outsideWhile
insideWhileBefore
Exception calling "FindItems" with "1" argument(s): "The request failed. The remote server returned an error: (501)" ........
insideWhileAfter
insideWhileBefore
<MAIL CONTENTS>
insideWhileAfter
Please help me out in understanding why this happening so and how I can overcome it.

When popen performs status check on service that dosen't exist error no results returned

I am attempting to use subprocess.Popen() to read a service status.
If I get an unrecognized service error the value, while printed to the screen, is not saved to out or err for later viewing.
If the service does exist, "is running" gets saved to the out value. I would like to accomplish the same results when the unrecognized error is encountered.
I have tried using subprocess.check_output but it is unrecognized.
If I use an existing service it works as desired.
My code:
p = subprocess.Popen(['service','PretendService','status'], stdout=subprocess.PIPE)
out,err = p.communicate()
You need to pipe stderr as well as stdout:
p = subprocess.Popen(['service','PretendService','status'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = p.communicate()
# Now err will have your error message

Status for connector session is: 1544 Message: Code # 0 Connector Message: Error: Cannot find Connector 'DB2'

I have a database with two agents, well there are really more than two, but two that matter right now. One works, the other does not. Both have Uselsx '*lsxlc' defined in (Options).
I have commented out everything in the failing agent except
Dim s As New NotesSession
Dim db As NotesDatabase
Dim agentLog As NotesLog
Set db = s.CurrentDatabase
'agent log
Set agentLog = New NotesLog("Customers from Aging Report - AKM")
Call agentLog.OpenNotesLog( db.server, "agentinfo.nsf" )
agentLog.LogActions = True 'Set to True/False to turn on/off action logging
agentLog.LogErrors = True 'Set to True/False to turn on/off error logging
Call agentLog.LogAction("Start Agent: GetCustomerDataBasedOnAging")
On Error Goto throwError
Dim lcses As New LCSession
Dim src As New LCConnection(COutConn)
%REM
....
%END REM
Exit Sub
throwError:
'Error code
Dim epos As String
Dim emsg As String
Dim msg As String
Dim result As String
Dim status As Integer
Dim msgcode As Long
If lcses.status <> LCSUCCESS Then
status = lcses.GetStatus (result, msgcode, msg)
Call agentLog.LogError( msgcode,"Status for connector session is: " & Cstr(status) & Chr(10) & "Message: " & msg & " Code # " & Cstr(msgcode) & Chr(10) & "Connector Message: " & result )
emsg = "Customers from Aging Report' Agent: ("+Cstr(Erl)+") "& "[" &Cstr(Err) & "] [" & Error$ & "]"
Call agentLog.LogError( Err, emsg)
Else
emsg = "Customers from Aging Report' Agent: ("+Cstr(Erl)+") "& "[" &Cstr(Err) & "] [" & Error$ & "]"
Call agentLog.LogError( Err, emsg)
End If
Resume Next
COutConn is defined as a constant with value 'DB2'
I get the following error in the agent log:
Status for connector session is: 1544
Message: Code # 0
Connector Message: Error: Cannot find Connector 'DB2'
This happens whether I use the constant COutConn, or "DB2".
The strange thing is that the other agent with the same definitions works properly. I know DB2 exists on the machine, it is i5/OS v5r4. DB2 is built in on this operating system.
What else do I need to look for?
The answer is, be sure you know which machine the agent is running on. When you right click the agent in Domino Designer, and select Run, as I did, the agent is not running on the server that the database resides on, but rather inside the Domino Designer client. that is going to be Windows or Linux depending on your workstation.
So why did the one agent work while the other did not? Well the one that worked was activated from a button in the Notes Client, and the function attached to the button used Run on Server. The server was indeed IBM i. However, in the case of the failing agent, I executed that one from within Domino Designer as mentioned above, thus no DB2 connector.
Here's to hoping someone can learn from my pain!

How do I get topshelf to return error code when command fails?

I am trying to start my service with powershell but currently it fails. I don't know why it fails but that is not the point here. When trying to start the host all I don't get the correct exit code so my automatic deploy fails silently.
What I'm trying to do is:
$cmd = "$folder" + "\MyService.exe"
try
{
& $cmd stop
& $cmd uninstall
& $cmd install
& $cmd start
}
catch
{
Write-Host "Error: Update of service failed"
exit 1
}
The start command fails with the following messge:
Topshelf.Hosts.StartHost Error: 0 : The service failed to start., System.InvalidOperationException: Cannot start service MyService on computer '.'. ---> System.ComponentModel.Win32Exception: The service cannot be started, either because it is disabled or because it has no enabled devices associated with it
--- End of inner exception stack trace ---
at System.ServiceProcess.ServiceController.Start(String[] args)
at System.ServiceProcess.ServiceController.Start()
at Topshelf.Runtime.Windows.WindowsHostEnvironment.StartService(String serviceName)
at Topshelf.Hosts.StartHost.Run()
and I never get into the catch statement of my powershell script.
UPDATE:
Note that I am asking for how to get the method to the catch statement and not the solution to the actual exception. I have solved the actual exception but I want better feedback in the future if it fails, and that is want the catch statement to be executed which it isn't in case of error.
try/catch in PowerShell doesn't work with exe.
After myservice.exe calls you need to check the automatic variable $LastExitCode.
Try something like this:
$out = & $cmd start
if ($LastExitCode -ne 0) # if exe returns 0 on success, if not change the condition accordingly
{
"ERROR: $out"
return # to exit script or do something else.
}

How do I get detailed PostgreSQL-errors in Access via ODBC?

Is there a way to get the detailed error-messages PostgreSQL shows when running a query from command-line or a client like PG-Admin when using the ODBC-Interface-Driver?
The Err-object in Access just tells you that something went wrong but is not very helpful - I have to run the same query again in PG-Admin to see where the problem is.
Silly me! Just have to iterate through the Errors-object...
Dim errX As DAO.Error
Dim strError As String
For Each errX In DAO.Errors
strError = strError & "# >> " & errX.number & " | txt >> " & _
errX.DESCRIPTION & Chr(10) & Chr(10)
Next errX