Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

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

Posted on by Microsoft Employee

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

  • Verified answer
    Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Get SQL connection string or run sp or query using VS Tools for GP

    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;

           }

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Get SQL connection string or run sp or query using VS Tools for GP

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get SQL connection string or run sp or query using VS Tools for GP

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

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Get SQL connection string or run sp or query using VS Tools for GP

    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.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans