3

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.

Please note this has also been posted on the Sage Canada Community forum.

Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
MikeG001
  • 53
  • 4
  • When called from VB6, its definitely hitting the correct instance of your C# code? eg if you set a breakpoint in the IDE it will be hit? If it were calling some other out of data assembly that could be a problem. – StayOnTarget Apr 28 '23 at 14:35
  • It is being hit. – MikeG001 Apr 28 '23 at 14:50
  • 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. – MikeG001 Apr 28 '23 at 15:06
  • 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? – MikeG001 Apr 28 '23 at 16:03
  • We thought using UNC naming for the path to the sample cpy worked but it's seems it no longer does. We're stumped. – MikeG001 Apr 28 '23 at 18:11
  • You might try using Process Monitor to watch the running program and see what its doing in terms of filesystem access - both to watch DLL/assembly loads but also the sample data files. That often can provide a useful clue. https://learn.microsoft.com/en-us/sysinternals/downloads/procmon – StayOnTarget Apr 28 '23 at 18:12
  • We reg'd all the Sage dll that come with the SDK to GAC, rebooted and it seems to connect but we will test more fully this week – MikeG001 Apr 29 '23 at 15:13

0 Answers0