CFRONTDOTNET Navision 2009 R2

Hello,
I am trying to connect via .net C# program to Nav server(SQL) getting the last transaction for a specific POS and then trying to connect to that POS (Native) by changing the CFRONT driver type, sometimes it's working and sometimes not I think cause I don't have 2 instance of the CFront object (the same Object is switching the driver type from SQL to native) hereby my function would you please help?
public void connectandcheck()
{
if (PosLocations == null || HoLocation == null)
{
throw new NullReferenceException();
}else{
NavisionValue HOData = new NavisionValue();
NavisionValue POSData = new NavisionValue();
foreach (Location l in PosLocations)
{
int tablehandle=0;
int recordHandle=0;
CFrontDotNet.NavisionPath = "C:\\Program Files (x86)\\LS Retail\\Data Director 3\\cfront\\602\\";
try
{

NavisionNetType HonetType = NavisionNetType.SqlDefault;

CFrontDotNet.DriverType = NavisionDriverType.Sql;
CFrontDotNet.Instance.ConnectServerAndOpenDatabase(HoLocation.getServerName(), HonetType, HoLocation.getDatabase(),
65000, false, false, HoLocation.getUsername(), HoLocation.getPassword());
CFrontDotNet.Instance.OpenCompany(HoLocation.getCompany());
tablehandle = CFrontDotNet.Instance.OpenTable(99001473);
recordHandle = CFrontDotNet.Instance.AllocRecord(tablehandle);
CFrontDotNet.Instance.SetFilter(tablehandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Store No."), "=" + l.getLocationName());
CFrontDotNet.Instance.FindLastRecord(tablehandle, recordHandle);
HOData = CFrontDotNet.Instance.GetFieldData(tablehandle, recordHandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Transaction
No."));
CFrontDotNet.Instance.CloseTable(99001473);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
}
catch (CFrontException ex)
{
messagetosend = messagetosend + "\r\n" + "Cannot Connect to HO while checking POS No." + l.getLocationName();
LogMessage.LogTheEvent("Error cannot Login to HO "+ ex.Message.ToString());
CFrontDotNet.Instance.CloseTable(tablehandle);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();

continue;
}

try
{


NavisionNetType Posnettype = NavisionNetType.NativeTcp;
CFrontDotNet.DriverType = NavisionDriverType.Native;
CFrontDotNet.Instance.ConnectServerAndOpenDatabase(l.getServerName(), Posnettype, l.getCompany(), 65000, false, false,
l.getUsername(), l.getPassword());
CFrontDotNet.Instance.OpenCompany(l.getCompany());
tablehandle = CFrontDotNet.Instance.OpenTable(99001473);
recordHandle = CFrontDotNet.Instance.AllocRecord(tablehandle);
CFrontDotNet.Instance.SetFilter(tablehandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Store No."), "=" + l.getLocationName());
CFrontDotNet.Instance.FindLastRecord(tablehandle, recordHandle);
POSData = CFrontDotNet.Instance.GetFieldData(tablehandle, recordHandle, CFrontDotNet.Instance.FieldNo(tablehandle,
"Transaction No."));
CFrontDotNet.Instance.CloseTable(99001473);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
if (HOData.ToString() != POSData.ToString())
{
int honumber = Int32.Parse(HOData.ToString());
int posnumber = Int32.Parse(POSData.ToString());
int difference = posnumber - honumber;

messagetosend = messagetosend + "\r\n" + "You have " + difference + " transactions difference between HO and POS No. on" +
l.getLocationName();
}

}
catch (CFrontException ex)
{
messagetosend = messagetosend + "\r\n" + "Cannot Connect to POS No. " + l.getLocationName()+ "Last Ho Transaction No.
"+HOData.ToString();
LogMessage.LogTheEvent("Error cannot Login to POS "+l.getLocationName()+" " + ex.Message.ToString());
CFrontDotNet.Instance.CloseTable(tablehandle);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();

continue;


}





}

Answers

  • krikikriki Member, Moderator Posts: 8,875
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision Classic Client' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2020: 19 & 20 November 2020, Antwerp (Belgium)
Sign In or Register to comment.