C# 使用GPConnNet.dll的SQL Server连接

C# 使用GPConnNet.dll的SQL Server连接,c#,microsoft-dynamics,dynamics-gp,econnect,C#,Microsoft Dynamics,Dynamics Gp,Econnect,我正在尝试使用GP当前登录的凭据连接到Dynamics GP SQL Server数据库。(上下文) 使用GPConnNet.dll文档中提供的代码,我应该能够获得连接,但对于非sa用户,sa和dynsa无法获得连接。我收到登录失败的sql server错误 SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder(connectionString); SqlConnection sqlConn = new SqlConnect

我正在尝试使用GP当前登录的凭据连接到Dynamics GP SQL Server数据库。(上下文)

使用GPConnNet.dll文档中提供的代码,我应该能够获得连接,但对于非sa用户,sa和dynsa无法获得连接。我收到登录失败的sql server错误

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.");
}
}
用户是否需要某些东西?GPConnection代码中是否有我遗漏的内容


谢谢

此类将检索连接所需的正确数据

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;
}
将GPUser.ConnectionString传递到此代码将创建一个有效的SQLConnection对象,您可以使用该对象连接到GP数据库

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.");
    }
}
SqlConnectionStringBuilder cb=新的SqlConnectionStringBuilder(connectionString);
SqlConnection sqlConn=新的SqlConnection();
if(sqlConn.State!=ConnectionState.Open)
{
GPConnection.Startup();
var gpconn=新的GPConnection();
gpconn.Init(,);
尝试
{
sqlConn.ConnectionString=string.Format(“数据库={0}”,cb.InitialCatalog);
gpconn.LoginCompatibilityMode=false;
Connect(sqlConn,cb.DataSource,cb.UserID,cb.Password);
如果(gpconn.ReturnCode!=1)
抛出新的AuthenticationException(“无法使用GP凭据进行身份验证”);
}
catch(System.Runtime.InteropServices.SEHException)
{
抛出新的AuthenticationException(“无法使用GP凭据进行身份验证”);
}
}

我正在使用GPUser类。我得到这个连接字符串:string connection=“data source=Dynamic GP 2010;initial catalog=TWO;persist security info=False;User ID=sa;Password=123”;但是我得到了登录错误。这是作为动态GP 2010的正确数据源吗?是的,看起来差不多正确,“动态GP 2010”是默认的动态GP ODBC32连接名称。你有什么例外?谢谢你的回复!数据源名称不是“Dynamic GP 2010”,即sql数据源名称。如果我对DYNAMCI数据库使用这个连接字符串:Data Source=Rohri;初始目录=两个;持久安全信息=False;用户ID=client1。这很好用。如果使用相同的连接字符串而不是动态连接字符串,则使用两个数据库。“client1”登录失败。您能告诉我为什么只有两个数据库出现错误吗。
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.");
    }
}