Sunday, March 1, 2015

Dynamics GP GPConnNet ReturnCode 131074: One possible cause

By Steve Endow

Last week a customer contacted me saying that an eConnect integration suddenly stopped working.

They have been using the integration for a few years without issue, but without apparent explanation, it started returning an error of "ExecuteNonQuery requires an open and available connection".

The error message is pretty straightforward--the integration was failing to get a connection to SQL Server, but we didn't know why.

The client said that the only change they made was resetting the password for the GP user who was using the integration.  Despite numerous attempts to figure out the cause, I was unable to figure out why GPConnNet was not returning an open database connection.

Well today, while working on a different eConnect integration, I suddenly had the same problem.  GPConnNet was not returning an open connection.

After stepping through my code line by line, I found that GPConnNet was returning a ReturnCode value of 131074.

    GPConnection GPConnObj = new GPConnection();

    GPConnObj.Init("key1", "key2");
    gpConn.ConnectionString = "DATABASE=" + gpDatabase;
    GPConnObj.Connect(gpConn, gpServer, gpUser, gpPassword);

    //Check for error from GPConnNet
    if ((GPConnObj.ReturnCode & (int)GPConnection.ReturnCodeFlags.SuccessfulLogin) != (int)GPConnection.ReturnCodeFlags.SuccessfulLogin)
        Log.Write("Failed to get SQL connection from GPConnNet", true);
        return null;


I found the GPConnNet documentation, which listed the following return codes:

Constant                  Value                Description
SuccessfulLogin           1                    A connection was created
FailedLogin               2                    A connection could not be created
ExceptionCaught           131072 (&H20000)     An exception occurred during the connection attempt
PasswordExpired           65536 (&H10000)      The user’s password has expired

So, I'm not sure what my ReturnCode of 131074 meant.  Is it a combination of FailedLogin and ExceptionCaught? (131072 + 2)  Even if it is, what does that mean?

I knew the GP login was valid, since I had just created it.

And then it dawned on me.  What if I had forgotten to give the user access to the GP company databases?

Sure enough, I had forgotten to give my "gpimport" user access to my company databases.  I normally use the "Copy Access" button on the user window, but I think I got distracted while creating this user and forgot to copy the access.

Once I gave the user access, GPConnNet provided an open database connection.

I'm now wondering if my client has the same issue.  I'll be following up with them to see if they might have created a new company database or a test company database and they didn't grant access to the GP user being used by my integration.

Steve Endow is a Microsoft MVP for Dynamics GP and a Dynamics GP Certified IT Professional in Los Angeles.  He is the owner of Precipio Services, which provides Dynamics GP integrations, customizations, and automation solutions.

You can also find him on Google+ and Twitter

No comments: