Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

From VBA how can we determine which SQL server a user is accessing?

Posted on by 1,325

On our client machines we do not have separete file folders and client installations for our production and test environments. We have custom Windows / VBA we need to make sure is pointing to production data when the user signed on to GP and selected the production server name from the server list. Likewise when they select the test server from the server list we want to make sure they are pointing to test data on the test server. We would like for the VBA to be able to use some environment variable or table field to determine which server / environment the user selected from the server list.

 

We have separate ODBC system DSN data sources defined for the production and test SQL servers on the client machines. I looked at SY02100 but it does not contain the SQL server names, just server ID’s . Any help with this question would be appreciated.

*This post is locked for comments

  • Tom Cruse Profile Picture
    Tom Cruse 1,475 on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    Gotcha, looks like Ian was right on :)

    I didn't understand your setup, makes sense now.

  • Larry Turner Profile Picture
    Larry Turner 1,325 on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    Richard,

    Thank you for your response. I will ask our VBA developer to let me know which approach they ultimately use so that I can verify the answer here. I'm not a VBA developer myself.

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    In my Visual Studio applications I use GPConnNet and you can get the data source name using

    Dynamics.Globals.SqlDataSourceName.Value

    If this can be used using VBA then if you name your DSN using the server name that should give you what you need.

  • Larry Turner Profile Picture
    Larry Turner 1,325 on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    Tom,

    We have a production and test version of the same company on different servers. We need for the VBA to determine which server the user logged into when they signed into GP.

    Thank you for your interest and help.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    Ian is right, unless your code do things differently based on the server it connects to

  • Verified answer
    Ian Grieve Profile Picture
    Ian Grieve 22,782 on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    You can use UserInfoGet in VBA to create an database connection to the server the user is logged into without the need for any manual connections; using UserInfoGet eliminates the possibility of your VBA connecting to the wrong server.

  • Suggested answer
    Tom Cruse Profile Picture
    Tom Cruse 1,475 on at
    RE: From VBA how can we determine which SQL server a user is accessing?

    Larry are you saying that when a user logs in to GP the companies they're selecting from might be residing in a different server??

    That drop-down list displays the Company Names from SY01500 all from the same server and instance.

    Is what I mentioned above correct, or there something else that I'm missing?

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans