问题
Is there any way to get an ODBC-Connection to an ( external ) table from AX2012R2, without using a DSN in the ODBC-connections?
It worked fine in 2009 with something like
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);
}
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.
Edit:
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.
回答1:
Why not make a system or user DSN?
This will establish a driver for the connection. You do not need to specify server or database.
回答2:
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');
来源:https://stackoverflow.com/questions/20346179/odbc-connection-to-external-data