Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

GP Connect Dll connection issue

Posted on by Microsoft Employee

Hi Guys,

I am working on integration of my .net application with microsoft GP using GP connect dll for database connection. But it is not connecting to database and returning 2 as end result. After doing analysis of code i found that this happening because my init method in GP connect dll is returning 7.as given below. Init method is return 7 in response variable. Please suggest when it return 7 and when it returns 0.

static void Main(string[] args)

            {

                  OdbcConnection cn = new OdbcConnection();

                  OdbcCommand cmd = new OdbcCommand();

                  OdbcDataReader rst;

                  Int32 resp;

                  GPConnection GPConnObj;

 

                  // Call Startup

                  resp = GPConnection.Startup();

 

                  // Create the connection object

                  GPConnObj = new GPConnection();

 

                  // Initialize

                int response=  GPConnObj.Init("<Key1>", "<Key2>");

 

                  // Make the connection

                  cn.ConnectionString = "DATABASE=TWO";

                  GPConnObj.Connect(cn, "LocalServer", "LESSONUSER1",

                  "access");

 

                  // Check the return code

                  if ((GPConnObj.ReturnCode &

                  (int)GPConnection.ReturnCodeFlags.SuccessfulLogin) ==                   (int)GPConnection.ReturnCodeFlags.SuccessfulLogin)

                  {

                        // Specify the command retrieve all customers

                        cmd.Connection = cn;

                        cmd.CommandText = "Select * From RM00101";

 

                        // Execute the command

                        rst = cmd.ExecuteReader();

                        rst.Read();

 

                        // Display the name of the first customer

                        Console.WriteLine(rst.GetValue(1).ToString());

                        Console.ReadLine();

 

                        // Close the connection

                        cn.Close();

                  }

                  else

                  {

                        Console.WriteLine("Login failed");

                        Console.ReadLine();

                  }

          

                  // Dispose of the connection object

                  GPConnObj = null;

 

                  // Call Shutdown

                  resp = GPConnection.Shutdown();

            }

      }

Thanks

Amit Kumar

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: GP Connect Dll connection issue

    Thanks andrew, I got this because the key are incorrect, Microsoft provided new keys to us now it is working. thanks for your help.

  • Suggested answer
    Andrew John Dean Profile Picture
    Andrew John Dean 1,337 on at
    RE: GP Connect Dll connection issue

    Hi Amit

    Here is the code I use to read database tables

    public void ExecuteDataSet(ref DataTable dataTable, string database, CommandType commandType, string commandText, SqlParameter[] sqlParameters)
    {
      GPConnection.Startup();
      GPConnection GPConnObj = new GPConnection();
      SqlConnection sqlConnection = new SqlConnection();
      try
      {
        sqlConnection.ConnectionString = "Database = " + database;
        GPConnObj.Init("XXX", "XXX");
        GPConnObj.Connect(sqlConnection, server, userID, password);
        SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection);
        sqlCommand.CommandType = commandType;
        sqlCommand.CommandTimeout = 120;
        if (sqlParameters != null)
        {
          foreach (SqlParameter sqlParameter in sqlParameters)
          {
            sqlCommand.Parameters.Add(sqlParameter);
          }
        }
        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
        sqlDataAdapter.Fill(dataTable);
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        sqlConnection.Close();
        GPConnObj = null;
        GPConnection.Shutdown();
      }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans