0
我正在嘗試使用當前從GP登錄的憑據連接到動態GP SQL Server數據庫。 (對於上下文http://blogs.msdn.com/b/developingfordynamicsgp/archive/2008/10/02/why-does-microsoft-dynamics-gp-encrypt-passwords.aspx)使用GPConnNet.dll的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.");
}
}
連接字符串中的信息來自Microsoft Dexterity工具包。
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
};
}
}
}
用戶需要什麼嗎?我錯過了GPConnection代碼中的某些內容嗎?
謝謝
我正在使用GPUser類。我得到這個連接字符串:string connection =「data source = Dynamic GP 2010; initial catalog = TWO; persist security info = False; User ID = sa; Password = 123」;但我正在登錄error.Is這個正確的數據源作爲動態GP 2010。 – 2012-09-05 12:50:27
是的,看起來正確的「動態GP 2010」是默認的動態GP ODBC32連接名稱。 你得到的例外是什麼? – dustinchilson 2012-09-07 00:06:05
謝謝你的回覆!數據源名稱不是「Dynamic GP 2010」,即sql數據源名稱。如果我使用DYNAMCI數據庫的此連接字符串:Data Source = Rohri; Initial Catalog = TWO; Persist Security Info = False; User ID = client1。這工作正常。如果我使用相同的連接字符串而不是DYNAMIC,則使用TWO數據庫。我得到「client1」的錯誤登錄失敗。你可以告訴我爲什麼我只爲兩個數據庫收到錯誤。 – 2012-09-07 09:20:54