"Unable to open company file" message returned

Hi all,

We're developing a  COM-aware .Net assembly that is used in a legacy VB6 app and keep getting the above message when opening a connection via SDKInstanceManager.Instance.OpenDatabase. When we call our method from inside another .Net assembly this does not happen, the call to open works fine. Below is the class we use:

    [ComVisible(true)]

    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComSourceInterfaces(typeof(IMyClass_ThreadedEvents))]
    [Guid("A8F518D8-6446-11E2-BC88-724F6188709B")]
    public class MyClass : IDisposable
    {    
        public string OpenConnection()
        {
            string retVal = string.Empty;

            try
            {
                retVal = "OpenConnection|@@|*NOERROR*|@@|*ALLOK*|@@||@@|";

                string conInstallFolder = @"C:\Users\Public\Documents\Simply Accounting\2017\Samdata\Pro";
                string conCompany = "Universl";
                string conUserName = "sysadmin";
                string conPassword = "12345";
                string conVersName = "Sage 50 Accounts";
                string conVersNumber = "2017";
                string conVersCountry = "Canada";

                bool allok = SDKInstanceManager.Instance.OpenDatabase(conInstallFolder + @"\" + conCompany + ".SAI", conUserName, conPassword, true,
                    conVersName + " " + conVersNumber + " " + conVersCountry, "SASDK", 1);
            }
            catch (Exception ex)
            {
                retVal = "OpenConnection|@@|*ERROR*|@@|" + ex.Message;
            }
            return retVal;
        }
    }

My VB6 code:

Private Function RunTestTasks()

Dim MyClass As New MyDLL.MyClass
Dim retval As String

retval = MyClass.OpenConnection()

Call MyClass.CloseConnection

Set MyClass = Nothing

End Function

The .Net assembly only references Sage_SA.SDK, Sage_SA.Domain and Sage_SA.Domain.Utility and targets x86. No instances of Sage or app is accessing the company file. The VB6 code runs as Windows administrator.

Is there anything we're missing? We're stuck and would like to fix this issue. Many thanks.

  • 0

    If I use a unc path I seem to be able to go further but now get Could not load file or assembly 'Sage_SA.Work. I tried putting this file into GAC by registering it using gacutil and not doing so but build the .Net assembly with this file as reference but the error persists in both scenarios. Any idea? Thanks.

  • 0

    The Work assembly is in GAC_32 after I register it but VB6 still complains it is missing:

    Could not load file or assembly 'Sage_SA.Work, Version=1.0.0.1, Culture=neutral, PublicKeyToken=04796331da23c125' or one of its dependencies. The system cannot find the file specified.

    What bare-minimum assemblies do I need to register for this to work? Am not seeing a lot of activity on this forum.

  • I'm not sure I am going to be any help but the problem seems to stem from connecting the VB6 app to the com dll.  So all I have are questions to look at, I don't have the answers.

    1) Does the com dll need a Declare Function statement in your VB6 app is correct or are you referencing directly to the dll?

    2) Because you are using the 2017 version of the Canadian Sage 50 program, do you have the correct SDK including the suffix eg. 2017.2 if your file is from 2017.2?

    3) Do you have the Sage 50 program installed on the machine you are running the program on?  Probably since it worked in a different program.

    4) When you do run it from within another .NET assembly do you see the process.pid file created under the *.saj folder?  This usually indicates the file is started and running.  You can also look for the mysqld.exe process in the windows Task list on the computer where the *.sai file is located.  When you close your program, the mysqld.exe process will disappear if no other program is accessing the database.

    5) Was your other .NET assembly also C#?  If so, what happens if you create a small VB.Net program to use the dll?  Will it work?

    Unfortunately, I can't really help directly with your programming.  I do program in VB.Net but I haven't touched VB6 since before 2010 and never did any interop and custom dll work with other languages to speak of.  I also gave up on using the SDK over 15 years ago because I didn't have enough programming knowledge to get it to work.  So none of my programming uses it.

  • 0 in reply to Richard S. Ridings

    Much appreciated. To reply:

    1/ The latter

    2/ Yes, 2017.0

    3/ Yes

    4/ Will check. Thanks

    5/ Yes it was. The assembly works fine if I create a small UI form that calls the assembly

    We're moving away from VB6 but a client came back with a request. Not sure why it worked before when he originally got the sw from us and it's giving such issues now. We developed it on Win 7 and so fired up a Win 7 machine but the behaviour is identical. Many thanks again.

  • 0 in reply to dynasoft uk

    Are you getting the error on the Universl sample file as your code indicates or are you having problems with their file too?  If it is their file as well, make sure the DataVersion in both *.sai flies is 24001 (when opened in Notepad).

    I believe with every update of the program a new SDK is required.

    Two other issues that come up.  I assumed these were not issues originally because you environment may not have changed but, has that password really set on the sample file?  And has the sysadmin user for that sample file also been set up with Third-Party rights that will allow another program to access the file under it's username?

    The image below indicates Read-only access but you may need Read/Write for your app.

  • 0 in reply to Richard S. Ridings

    4) When you do run it from within another .NET assembly do you see the process.pid file created under the *.saj folder? Yes the file appears

  • 0 in reply to Richard S. Ridings

    Your question is pertinent. the sw is able to connect on the client machine but is not performing all functionality for some reason. On our dev machine we can't even connect to the sample cpy. The radio button Read/write is ticked.

    We thought using UNC naming for the path to the sample cpy worked but it's seems it no longer does. We're stumped.

  • 0 in reply to dynasoft uk

    My logic for asking this is that a lack of error message does not necessarily mean the database started properly.  I was also assuming Sage 50 was closed at the time you ran your program test.

  • 0 in reply to Richard S. Ridings

    Yes we close the Sage 50 UI before we run the tests

  • 0 in reply to dynasoft uk

    I am afraid I am out of Hail Mary's.  The last one I have is an unlikely solution but the OpenDatabase method does have another overload.  I doubt this is the issue because you had it working at one point, but maybe trying the other one might lead you in the right direction.

    The only things to suggest is what you have probably already done.  Go back and double-check to make sure you are targeting x86, the proper .NET framework for Sage 50 2017 (I don't remember which one myself, I'd have to look into it to figure it out), and maybe create a small VB6 app that only triggers the dll.  When I end up with problems that have no explanation, I restart everything, including the computer and go back to basics, throw my original assumptions out the window and revalidate them all.  I eventually get to the answer.

    Sorry I can't be of more help.  Maybe if sees this thread, there might be more ideas forthcoming.

  • 0 in reply to Richard S. Ridings

    Thanks. I had done what you suggested but with the simple vb6 code I included at the outset. The actual code we use is more complex but even the simple Function I gave won't work. We'll keep hammering anyway. thanks for all the help and suggestions.