private static void Connect() { // Declare the Application object used to connect. Sage.Accounting.Application application = null; try { application = new Sage.Accounting.Application(); // Use the Connect method (no parameters required) application.Connect(); // IMPORTANT: select the company (database) - a connection will not be made // unless this line is included. // In this example an indexer is used to select the company. This // is fine if there is only one company. If there are multiple companies a more // appropriate solution would be to iterate the collection checking the Name property. application.ActiveCompany = application.Companies[0]; System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("Successfully logged on to " + application.ActiveCompany.Name); System.Diagnostics.Debug.WriteLine(stringBuilder.ToString()); } // The Connect method may throw the following exceptions: // Ex9990Exception - User already logged in. // Ex9991Exception - Maximum number of users logged in. catch (System.Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); } finally { if (application != null) { // Disconnect from the application application.Disconnect(); } } }