These are 2 scripts : one ASP and one PHP. Note that at the end of the ASP code, no objects are freed.
One clue may be that in php we must use
$oInvoicePost->Header->Fields['fieldname']
whereas in asp we use
oInvoicePost.Header["fieldname"]
perhaps PHP's implementation of this is flawed somehow ???
<?php
/*******************************************************************************************************
Simple SAGE SDO PHP script : running twice causes the web server to
hang
Running a GUI-based SDO application, e.g. Delphi COM server
issues the dialog about user already being logged on.
Clicking YES on this dialog causes the script to run correctly a
second time
and then hang when run a 3rd etc etc etc
Setting any properties of the $oInvoicePost object causes this error
i.e. if the following lines are commented out, the script runs many
times with no problem
$oInvoicePost->Type = intval(sdoLedgerInvoice);
$oInvoicePost->Header->Fields["INVOICE_NUMBER"]->Value =intval($oInvoicePost->GetNextNumber());
*
*********************************************************************************************************/
$random_seed = date("YmDnnss");
$unique_id = "sage_sky".$random_seed;
$oSDO = NULL;
$oWS = NULL;
$comobj_name = "sdoengine.10";
$oSDO = new COM($comobj_name) or tcf_throw_error ("Cannot connect to " .$comobj_name);
// create a new workspace
$oWS = $oSDO->Workspaces->Add($workspace_name);
// select the correct sage database
$sage_datapath = $oSDO->SelectCompany($installation_path);
// connect to the database
if (!($oWS->Connect($out, $sage_username, $sage_password,$unique_id))) {
tcf_throw_error ("Failed to connect to sage database at " .$sage_datapath);
}
$oSalesRecord = $oWS->CreateObject("SalesRecord");
$oInvoicePost = $oWS->CreateObject("InvoicePost");
$oStockRecord = $oWS->CreateObject("StockRecord");
$oInvoicePost->Type = intval(sdoLedgerInvoice);
$oInvoicePost->Header->Fields["INVOICE_NUMBER"]->Value =intval($oInvoicePost->GetNextNumber());
echo "INV NO : " .$oInvoicePost->Header->Fields["INVOICE_NUMBER"]->Value . "<hr/>";
if ($oInvoicePost->Update) {
echo "Invoice Posted OK";
}
else {
echo "Invoice <b>FAILED</b>";
}
// free all the objects we used
$oSalesRecord->Release;
$oSalesRecord = NULL;
$oInvoicePost->Release;
$oInvoicePost = NULL;
$oStockRecord->Release;
$oStockRecord = NULL;
// disconnect from sage and free the application objects
$oWS->Disconnect;
$oWS->Release;
$oWS = NULL;
$oSDO->Release;
$oSDO = NULL;
?>
Here is an ASP script which runs with no problems
<%
' Declare Objects
Dim oSDO
Dim oWS
Dim oInvoicePost
Dim oSalesRecord
Dim oStockRecord
' Declare Variables
Dim szDataPath
' Create the SDO Engine Object
Set oSDO = CreateObject("sdoengine.10")
' Create the Workspace
Set oWS = oSDO.Workspaces.Add("Example")
' Select Company. The SelectCompany method takes the program install
' folder as a parameter
szDataPath = oSDO.SelectCompany("C:\work\clients\sky market\sage\")
' A U.I. for company selection is presented to the user. If a company is selected,
' the path will be passed to the szDataPath variable.
' If not, or the Cancel button is selected, the variable will be left empty.
If szDataPath <> "" Then
' Try to Connect - Will throw an exception if it fails
If oWS.Connect(szDataPath, "MANAGER", "", "Example") Then
' Create an instance of the Objects
Set oSalesRecord = oWS.CreateObject("SalesRecord")
Set oInvoicePost = oWS.CreateObject("InvoicePost")
Set oStockRecord = oWS.CreateObject("StockRecord")
' Set the type of invoice for the next available number
oInvoicePost.Type = 261
' Use the GetNextNumber method
oInvoicePost.Header("INVOICE_NUMBER").Value = CLng(oInvoicePost.GetNextNumber)
Response.Write("New invoice number is " & oInvoicePost.Header("INVOICE_NUMBER").Value)
End If
End If
%>