ODBC连接到外部数据 [英] ODBC connection to external data
问题描述
有什么方法可以通过ODBC连接中的DSN 不从AX2012R2获取到(外部)表的ODBC连接?
Is there any way to get an ODBC-Connection to an ( external ) table from AX2012R2, without using a DSN in the ODBC-connections?
在2009年,类似这样的东西效果很好
It worked fine in 2009 with something like
systemInfo = SysSQLSystemInfo :: construct();
systemInfo = SysSQLSystemInfo::construct();
loginProperty = new LoginProperty();
loginProperty.setServer(systemInfo.getLoginServer());
loginProperty.setDatabase(systemInfo.getloginDatabase());
conString = strFmt( 'Driver={SQL Server Native Client 10.0};'
+ 'Server=%1;'
+ 'Database=%2;'
, systemInfo.getLoginServer()
, systemInfo.getloginDatabase()
);
if ( <someFunctionToCheckForTrusedConnectin> )
{
conString += '"Trusted_Connection=Yes;"';
}
else
{
conString += strFmt( '"id=%1;'
+ 'pwd=%2;"'
, _userName
, _passWord
);
}
loginProperty.setOther( conString );
try
{
odbc = new OdbcConnection( loginProperty);
}
catch
{
throw error(#DatabaseConnectionError);
}
但是它在2012年引发了错误:
But it throws errors in 2012:
Objekt 'OdbcConnection' konnte nicht erstellt werden.
[Microsoft][ODBC Driver Manager] Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben
我已经搜索了几个小时(也许是几天..),但没有找到任何可行的示例.
I've googled for hours ( maybe days.. ) and didn't find any working example yet.
如果我修改以下两行代码
If I modify the following two lines of code
loginProperty.setServer(systemInfo.getLoginServer());
loginProperty.setDatabase(systemInfo.getloginDatabase());
然后输入服务器/数据库为纯文本,乍一看似乎有效,但没关系,如果我输入了无效的用户名和/或密码.
and enter server / database as plain text, it seems to work on first look, BUT it doesn't matter, if I enter an invalid username and/or password.
推荐答案
我们所有的接口都使用此方法并且可以正常工作,我们将连接参数(即数据库名称和数据库服务器名称)存储在表中,请注意,DSN为已被注释掉,所以没有必要:
All our interfaces use this and it works, we store our connection parameters, ie database name and database server name in a table, note the DSN is commented out, so is not necessary:
loginProperty = new LoginProperty();
loginProperty.setServer(ImportJournalParameters.ExternalServerName);
// loginProperty.setDSN("ServerSQL10");
loginProperty.setDatabase(ImportJournalParameters.ExternalDBName);
connection = new OdbcConnection(loginProperty);
info('Login Process Successful - connection established');
这篇关于ODBC连接到外部数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!