How do I know if the connection to the database is open ?

I´m working with sage 50 CA 2016 SDK, and i have a problem with database connection.

When I run this code in a console application successfully opens the connection, but when I run the same code in a Winform application , does not open the connection, return false. 

And I have a theory, that is because the connection one way or another , is open. But I do not know how to get my connection status (open or closed ).

if (SDKInstanceManager.Instance.OpenDatabase(pSaiFile, pUsername, pPassword, false, "Sage 50 SDK Sample Program", "SASDK", 1))
{
      //Code

}


Somebody could help me? i´m working with C#.

Parents
  • 0
    The code is returning the success, or not, of instance.OpenDatabase. If the connection is already open, it may return a fail.

    If you have the Connection Manager taskbar program open, it should show the number of active connections. If a connection is currently open, the MySql Daemon should be running.

    After closing the application, or an SDK application, connections do stay open for a period of time before all files are closed. You'll notice this more if trying to apply a file attribute (i.e. Archive as in 'Attrib +A *.* /s') to the files in the data folder, or trying to eject a USB device.

    Some other wierdnesses:
    The SDK will accept a password string longer than 7 characters, but it won't just match the first 7 characters, it does whatever it does, on the whole string. (i.e. 'password' was being truncated by the user interface to 'passwor', but 'password' would fail)

    I would truncate all passwords to 7 char. The user name in the SDK seems to be case-sensitive - i.e. 'sysadmin' could log in, but SYSADMIN couldn't.

    I hope that helps, please post back!
  • 0 in reply to RandyW
    Definitely, it's right what you say about OpenDataBase() RandyW. But I have two different problems with this, the first is that I sometimes returns false, and the second is that I sometimes returns an exception which says: "Unable to open the company file.".

    And I'm trying to identify the "why?", Because when I run the same code in a console application does not give me any problems. but when I run it in a Winform application the aforementioned problems occur.
Reply
  • 0 in reply to RandyW
    Definitely, it's right what you say about OpenDataBase() RandyW. But I have two different problems with this, the first is that I sometimes returns false, and the second is that I sometimes returns an exception which says: "Unable to open the company file.".

    And I'm trying to identify the "why?", Because when I run the same code in a console application does not give me any problems. but when I run it in a Winform application the aforementioned problems occur.
Children
  • 0 in reply to Luis Marroquin

    False probably means a successful connection to the database, with a password / username failure. An exception 'Unable to open the company file' means a failure to establish a new connection to the database. Either it's already open in single user mode, or...?

    I can't tell you why it's behaving differently in a console vs winform application.  Possibly because of the command prompt environment running from a different current PATH?