web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Get SQL connection string or run sp or query using VS Tools for GP

(0) ShareShare
ReportReport
Posted on by

I have a need where I need to get data from a table that I created that I would like to run using the connection credentials GP is using.

How can I get the connection string using VS Tools for GP?

Or is there a way for VS tools run a query and retrieve a record set?

*This post is locked for comments

I have the same question (0)
  • Richard Wheeler Profile Picture
    75,850 Moderator on at

    Is this table inside the GP company database or in a database outside of GP? If you have installed VS Tools for GP you will have sample code showing you how to use GPConnNet. This will alow you to use the user ID and password from the user ID currently logged into GP. You add options to a screen by adding an Additional Button and then you access to all the fields on that screen. But first, you create a data connection using the GP user ID/Password and company ID. Let me know if you need specific examples.

  • Community Member Profile Picture
    on at

    Table is in GP Dynamics database. I'll look for those sample code. I might need some examples, though.

  • Richard Wheeler Profile Picture
    75,850 Moderator on at

    If you look through the the VS for GP documentation you will find example code. If you want I could paste a portion of my code in here next time.

  • Verified answer
    Richard Wheeler Profile Picture
    75,850 Moderator on at

    Here is the code I use to establish the connection

    You will need to register with Microsoft to get the license keys. I believe you can ask your partner to get you these keys.

       GPConnObj.Init("MyCompanyName", "MyLicenseKeys");

    private SqlConnection GetConnection()

           {

               SqlConnection DataConnection = new SqlConnection();

               /* Call Startup */

               resp = GPConnection.Startup();

               /* Create the connection object */

               GPConnObj = new GPConnection();

               /* Initialize the connection object */

               GPConnObj.Init("MyCompanyName", "MyLicenseKeys");

               /* Make the connection */

               DataConnection.ConnectionString = "Database=" + Dynamics.Globals.IntercompanyId.Value;

               GPConnObj.Connect(DataConnection, Dynamics.Globals.SqlDataSourceName.Value, Dynamics.Globals.UserId.Value, Dynamics.Globals.SqlPassword.Value);

               /* Check the return code */

               if ((GPConnObj.ReturnCode & (int)GPConnection.ReturnCodeFlags.SuccessfulLogin) !=

                   (int)GPConnection.ReturnCodeFlags.SuccessfulLogin)

               {

                   MessageBox.Show("Login failed");

               }

               return DataConnection;

           }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans