Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8354877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:41:36+00:00 2026-06-09T09:41:36+00:00

I am attempting to make a connection to a Dynamics GP SQL Server Database

  • 0

I am attempting to make a connection to a Dynamics GP SQL Server Database using the currently logged in credentials from GP. (for context http://blogs.msdn.com/b/developingfordynamicsgp/archive/2008/10/02/why-does-microsoft-dynamics-gp-encrypt-passwords.aspx)

Using the code provided from the documentation of GPConnNet.dll I should be able to get a connection but have been unable to do so for non-sa users, sa and dynsa work fine. I am receiving a login failed sql server error.

SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder(connectionString);
SqlConnection sqlConn = new SqlConnection();
if (sqlConn.State != ConnectionState.Open)
{
    GPConnection.Startup();
    var gpconn = new GPConnection();
    gpconn.Init(<Key1>, <Key2>);
try
{
    sqlConn.ConnectionString = string.Format("database={0}", cb.InitialCatalog);
    gpconn.LoginCompatibilityMode = false;
    gpconn.Connect(sqlConn, cb.DataSource, cb.UserID, cb.Password);
    if (gpconn.ReturnCode != 1)
         throw new AuthenticationException("Could not authenticate with the GP credentials.");
}
catch (System.Runtime.InteropServices.SEHException)
{
    throw new AuthenticationException("Could not authenticate with the GP credentials.");
}
}

The information in the connection string is coming from the Microsoft Dexterity toolkit.

public class GPUser
{
    public readonly static string DataBase = Dynamics.Globals.IntercompanyId.Value;
    public readonly static string UserID = Dynamics.Globals.UserName.Value;
    public readonly static string Password = Dynamics.Globals.SqlPassword.Value;
    public readonly static string DataSource = Dynamics.Globals.SqlDataSourceName.Value;
    public readonly static string ApplicationName = string.Format("{0}{1}", App.ProductName, "(gp)");
    public static string Server
    {
        get
        {
            //Returns the Server from the ODBC DSN
        }
    }
    public static SqlConnectionStringBuilder ConnectionString
    {
        get 
        {
            return new SqlConnectionStringBuilder
            {
                DataSource = Server,
                UserID = UserID,
                Password = Password,
                ApplicationName = ApplicationName,
                InitialCatalog = DataBase
            };
        }

    }
}

Is there something that is required on the user? Is there something in the GPConnection code that I’m missing?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:41:38+00:00Added an answer on June 9, 2026 at 9:41 am

    This Class will retrieve the proper data that you need for the connection.

    public class GPUser
    {
        public readonly static string DataBase = Dynamics.Globals.IntercompanyId.Value;
        public readonly static string UserID = Dynamics.Globals.UserId.Value;
        public readonly static string Password = Dynamics.Globals.SqlPassword.Value;
        public readonly static string DataSource = Dynamics.Globals.SqlDataSourceName.Value;
        public readonly static string ApplicationName = string.Format("{0}{1}", App.ProductName, "(gp)");
        public static SqlConnectionStringBuilder ConnectionString
        {
            get 
            {
                return new SqlConnectionStringBuilder
                {
                    DataSource = DataSource,
                    UserID = UserID,
                    Password = Password,
                    ApplicationName = ApplicationName,
                    InitialCatalog = DataBase
                };
            }
    
        }
        public readonly static short CompanyId = Dynamics.Globals.CompanyId.Value;
        public readonly static DateTime UserDate = Dynamics.Globals.UserDate.Value;
    }
    

    Passing GPUser.ConnectionString into this code will create a valid SQLConnection object that you can use to connect to the GP Database.

    SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder(connectionString);
    SqlConnection sqlConn = new SqlConnection();
    if (sqlConn.State != ConnectionState.Open)
    {
        GPConnection.Startup();
        var gpconn = new GPConnection();
        gpconn.Init(<Key1>, <Key2>);
        try
        {
            sqlConn.ConnectionString = string.Format("database={0}", cb.InitialCatalog);
            gpconn.LoginCompatibilityMode = false;
            gpconn.Connect(sqlConn, cb.DataSource, cb.UserID, cb.Password);
            if (gpconn.ReturnCode != 1)
                throw new AuthenticationException("Could not authenticate with the GP    credentials.");
        }
        catch (System.Runtime.InteropServices.SEHException)
        {
            throw new AuthenticationException("Could not authenticate with the GP credentials.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to connect to a SQL Server Compact Edition database from F#, and
I am attempting to make a simple connection to a remote database. I can
I am attempting to make a HTTPS connection to a website using HttpsURLConnection ,
I am attempting to make a simple connection to a MySql database, located on
I am attempting to insert a mass of records into SQL Server 2005 from
I'm attempting to insert rows into a SQL Server CE database, and it's returning
I'm attempting to make a simple query library and I'm using PDO for database
I am attempting to make my first mobile website by just using a different
I'm attempting to make a StateMachine execute some database action between states. So I
I'm attempting to make my networked application work locally (with both the server and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.