Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Accpac session from Windows Service

Status
Not open for further replies.

oxie18

Programmer
Feb 17, 2015
40
CA
Hi,

Anyone had experience opening an Accpac session from a Windows service. I created a windows service that monitors a folder for new CSV files. The service will read the file and prints either an Order Confirmation, Quote, Picking slip or Invoice depending on the document type indicated for that order in the CSV file. I have installed the windows service and works perfectly fine but I could not create a session connecting to Accpac (Session could not be opened - at AccpacCOMAPI.IAccpacSession.Open(String UserIdentifier, String Password, String DataBase, DateTime SessionDate, Int32 Flags, String Reserved). I have set the Account property of the ServiceProcessInstaller to LocalService. What might be the problem?

Code:
 Public Function ConnectToSession() As Boolean 'taking parameters here

        Dim booRetVal As Boolean = False

        Try
            mSession = New AccpacCOMAPI.AccpacSession
            'Opens AS Control view
            mSession.Init("", "OE", "OE0520", My.Settings.AccpacVersion)
            'mSession.Open(clsUtil.Decrypt(My.Settings.AccpacUser), clsUtil.Decrypt(My.Settings.AccpacPassword), My.Settings.AccpacCompany, System.DateTime.Now, 0, "")
            mSession.Open("ADMIN", "ADMIN", My.Settings.AccpacCompany, System.DateTime.Now, 0, "")

            If mSession.IsOpened Then
                CompanyName = My.Settings.AccpacCompany
                'LogMessage("Connected to company: " & mSession.CompanyName, False, EventLogEntryType.Information)
                booRetVal = True
            Else
                CompanyName = ""
                booRetVal = False
                'LogMessage("Failed to connect to " & AccpacCompanyID, False, EventLogEntryType.Information)
            End If

        Catch ex As Exception
            clsUtil.ErrorHandler(AccpacErrorHandler(mSession), "ConnectToSession", True)
        End Try

        Return booRetVal

    End Function
 
Is it something to do with the session date?
 
I tried hardcoding the session date to today's date (#3/23/2015#) but still I'm getting the same error.
 
Try hard code SQLL62 instead of My.Settings.AccpacCompany in
mSession.Open("ADMIN", "ADMIN", My.Settings.AccpacCompany, System.DateTime.Now, 0, "")

Sage 300 ERP Certified Consultant
 
I have hardcoded each and every parameter in the mSession.Open() but still I could not connect.
 
I'm still getting the same error using the ProgramName "XY1000" :(. Do I need to have a specific setting to make with the windows service?
 
Sample data doesn't typically work with 'today'. Push that date out to 2020.

Also - make sure that your SharedData folder and ProgramFiles folders are not using mapped drives and that the service has the right security context to be able to access the files in those folders.

You might also have to ensure that the account that the service is login in as also has their own Desktop folder (c:\users\<userid>\desktop). It sounds odd but sometimes services and other scheduled apps need that folder to function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top