没有 Active Directory 用户的 AX 2012 ODBC 连接
AX 2012 ODBC Connection Without Active Directory user
我在尝试使用 Microsoft Dynamics AX 连接到外部数据库时遇到问题。
我已经配置了 dsn,我可以连接 sql 服务器身份验证(不是活动目录,因为在另一台服务器上),当我测试时,它正常工作。
但是当我尝试在 x++ 中使用 dsn 时,我将正确的用户和密码发送到 loginProperty,但总是 return 错误,它尝试使用活动目录用户。
这是我的代码:
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql, criteria;
SqlStatementExecutePermission perm;
TLExternalUser tlExternaUser;
TLExternalUserPwd tlExternalUserPwd;
str strConnectionString;
str dsn = "myDsnName";
str dsnUser = "sqlUser";
str dsnUSerPwd = "sqlPWD";
strConnectionString = strfmt("UID=%1;PWD=%2",dsnUser,dsnUSerPwd);
loginProperty = new LoginProperty();
loginProperty.setDSN(dsn);
loginProperty.setDatabase("MyDatabase");
loginProperty.setOther(strConnectionString);
odbcConnection = new OdbcConnection(loginProperty);
if (odbcConnection)
{
info("success");
}
else
{
throw error("Failed to log on to the database through ODBC.");
}
但是我收到这个错误:
[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'DOMAIN\ACTIVEDIRECTORYUSER'.
我想直接将用户名和密码传递给我的 loginProperty,但是这样的方法不存在。
我怎样才能让它发挥作用?
尝试将其更改为此并删除 loginProperty.setDSN(...)
:
strConnectionString = strfmt("DSN=%1;UID=%2;PWD=%3",dsn, dsnUser,dsnUSerPwd);
loginProperty = new LoginProperty();
loginProperty.setDatabase("MyDatabase");
loginProperty.setOther(strConnectionString);
编辑 如果您的密码中有特殊字符,您需要使用反斜杠转义它们 \
或在它们之前放置一个 @
符号表示字符串文字的引号,例如 str myPass = @'MyP@ssw0rd';
.
我无法使它与 dsn 一起工作,所以我使用服务器,以这种方式:
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql ;
SqlStatementExecutePermission perm;
TLExternalUser tlExternaUser;
TLExternalUserPwd tlExternalUserPwd;
str strConnectionString;
str dbServer = 'myipServer';
str serverDbUser = 'myUser';
str serverDbUserPwd = 'MyPassword';
strConnectionString = strfmt("UID=%1;PWD=%2",serverDbUser,serverDbUserPwd);
loginProperty = new LoginProperty();
loginProperty.setServer(dbServer);
loginProperty.setDatabase("MyDatabase");
loginProperty.setOther(strConnectionString);
odbcConnection = new OdbcConnection(loginProperty);
我不明白为什么用 dsn 不起作用
我在尝试使用 Microsoft Dynamics AX 连接到外部数据库时遇到问题。
我已经配置了 dsn,我可以连接 sql 服务器身份验证(不是活动目录,因为在另一台服务器上),当我测试时,它正常工作。
但是当我尝试在 x++ 中使用 dsn 时,我将正确的用户和密码发送到 loginProperty,但总是 return 错误,它尝试使用活动目录用户。
这是我的代码:
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql, criteria;
SqlStatementExecutePermission perm;
TLExternalUser tlExternaUser;
TLExternalUserPwd tlExternalUserPwd;
str strConnectionString;
str dsn = "myDsnName";
str dsnUser = "sqlUser";
str dsnUSerPwd = "sqlPWD";
strConnectionString = strfmt("UID=%1;PWD=%2",dsnUser,dsnUSerPwd);
loginProperty = new LoginProperty();
loginProperty.setDSN(dsn);
loginProperty.setDatabase("MyDatabase");
loginProperty.setOther(strConnectionString);
odbcConnection = new OdbcConnection(loginProperty);
if (odbcConnection)
{
info("success");
}
else
{
throw error("Failed to log on to the database through ODBC.");
}
但是我收到这个错误:
[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'DOMAIN\ACTIVEDIRECTORYUSER'.
我想直接将用户名和密码传递给我的 loginProperty,但是这样的方法不存在。
我怎样才能让它发挥作用?
尝试将其更改为此并删除 loginProperty.setDSN(...)
:
strConnectionString = strfmt("DSN=%1;UID=%2;PWD=%3",dsn, dsnUser,dsnUSerPwd);
loginProperty = new LoginProperty();
loginProperty.setDatabase("MyDatabase");
loginProperty.setOther(strConnectionString);
编辑 如果您的密码中有特殊字符,您需要使用反斜杠转义它们 \
或在它们之前放置一个 @
符号表示字符串文字的引号,例如 str myPass = @'MyP@ssw0rd';
.
我无法使它与 dsn 一起工作,所以我使用服务器,以这种方式:
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql ;
SqlStatementExecutePermission perm;
TLExternalUser tlExternaUser;
TLExternalUserPwd tlExternalUserPwd;
str strConnectionString;
str dbServer = 'myipServer';
str serverDbUser = 'myUser';
str serverDbUserPwd = 'MyPassword';
strConnectionString = strfmt("UID=%1;PWD=%2",serverDbUser,serverDbUserPwd);
loginProperty = new LoginProperty();
loginProperty.setServer(dbServer);
loginProperty.setDatabase("MyDatabase");
loginProperty.setOther(strConnectionString);
odbcConnection = new OdbcConnection(loginProperty);
我不明白为什么用 dsn 不起作用