Adam007
Programmer
- Oct 18, 2009
- 21
Hey All,
I have an application that i have built and tested on 4 different machines (XP, Vista, Server 2008, Windows 7).
The application is built in C# and i haven't had an issue in my test environments.
Now that we are ready to start testing on the client machines, we are getting an error logging into Accpac using the XAPI, but for some strange reason the COMAPI is logging in fine.
I know what your all thinking, "Just use the COMAPI and be done with it". This isn't going to work for me, i need to use the CS0120 view to execute custom queries in Accpac and the COMAPI doesn't support this view.
I even went as far as building a test application that logs in with both the XAPI and COMAPI, and that shows that the COMAPI can log in fine but not the XAPI.
Here is the code for the log in test app;
Any help would be greatly appreciated, the client machines are all running XP SP3 with all the latest updates.
I have an application that i have built and tested on 4 different machines (XP, Vista, Server 2008, Windows 7).
The application is built in C# and i haven't had an issue in my test environments.
Now that we are ready to start testing on the client machines, we are getting an error logging into Accpac using the XAPI, but for some strange reason the COMAPI is logging in fine.
I know what your all thinking, "Just use the COMAPI and be done with it". This isn't going to work for me, i need to use the CS0120 view to execute custom queries in Accpac and the COMAPI doesn't support this view.
I even went as far as building a test application that logs in with both the XAPI and COMAPI, and that shows that the COMAPI can log in fine but not the XAPI.
Here is the code for the log in test app;
Code:
class Program
{
static string UserName = string.Empty;
static string Password = string.Empty;
static string DB = string.Empty;
static void Main(string[] args)
{
Console.Write("Enter the User Name:");
UserName = Console.ReadLine();
Console.Write("Enter the Password:");
Password = Console.ReadLine();
Console.Write("Enter the Database:");
DB = Console.ReadLine();
Console.Write("Attempting to log in with the XAPI:");
LogInWithXAPI();
Console.WriteLine();
Console.Write("Attempting to log in with the COMAPI:");
LogInWithCOMAPI();
Console.WriteLine();
Console.Write("Press Enter To Close");
Console.ReadLine();
}
private static void LogInWithXAPI()
{
ACCPACXAPILib.xapiSession pSession = new ACCPACXAPILib.xapiSession();
try
{
pSession.Open(UserName, Password, DB, DateTime.Today, 0);
Console.Write("Sucessful");
pSession.Close();
}
catch(Exception ex)
{
Console.Write("Failed" + Environment.NewLine);
string xapiErr = GetXAPIError(pSession);
if (!string.IsNullOrEmpty(xapiErr))
Console.WriteLine(xapiErr);
else
Console.WriteLine(ex.Message);
}
}
private static void LogInWithCOMAPI()
{
AccpacCOMAPI.AccpacSession pSession = new AccpacCOMAPI.AccpacSession();
AccpacCOMAPI.AccpacDBLink pDBLink;
try
{
pSession.Init("", "XX", "XX1000", "55A");
pSession.Open(UserName, Password, DB, DateTime.Today, 0, "");
Console.Write("Sucessful");
pDBLink = pSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
pDBLink.Close();
pSession.Close();
}
catch(Exception ex)
{
Console.Write("Failed" + Environment.NewLine);
string comErr = GetCOMAPIError(pSession);
if (!string.IsNullOrEmpty(comErr))
Console.WriteLine(comErr);
else
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// Gets any XAPI errors and clears them from the XAPI
/// </summary>
/// <returns></returns>
private static string GetXAPIError(ACCPACXAPILib.xapiSession sess)
{
long lCount;
int iIndex;
string ret = string.Empty;
try
{
if (sess.Errors != null)
{
lCount = sess.Errors.Count;
if (lCount != 0)
{
for (iIndex = 0; iIndex < lCount; iIndex++)
{
ret += sess.Errors.Item(iIndex).Description;
}
sess.Errors.Clear();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return ret;
}
private static string GetCOMAPIError(AccpacCOMAPI.AccpacSession sess)
{
long lCount;
int iIndex;
string ret = string.Empty;
try{
if (sess.Errors != null)
{
lCount = sess.Errors.Count;
if (lCount != 0)
{
for (iIndex = 0; iIndex < lCount; iIndex++)
{
ret += sess.Errors.Item(iIndex);
}
sess.Errors.Clear();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return ret;
}
}
Any help would be greatly appreciated, the client machines are all running XP SP3 with all the latest updates.