Цитата:
Сообщение от
Dark Light
Точно можно сделать это через ODBCConnection и админскую учетку:
X++:
ODBCConnection connection;
LoginProperty loginProp;
SysSQLSystemInfo systemInfo = SysSQLSystemInfo::construct();
Statement statement;
Resultset resultSet;
str otherStr;
str sqlState;
;
loginProp = new LoginProperty();
otherStr += "DRIVER={SQL Server}";
otherStr += ";Trusted_Connection=No";
otherStr += strfmt(";SERVER=%1", systemInfo.getLoginServer());
otherStr += strfmt(";DataBase=%1", systemInfo.getloginDatabase());
otherStr += strfmt(";UID=%1", 'Admin');
otherStr += strfmt(";PWD=%1", 'AdminPass');
loginProp.setOther(otherStr);
connection = new ODBCConnection(loginProp);
sqlState = strfmt('SELECT TOP 1 [RECID] FROM [%1].[dbo].[%2]',
systemInfo.getloginDatabase(),
tableStr(SysClientSessions));
statement = connection.createStatement();
new SqlStatementExecutePermission(sqlState).assert();
resultSet = statement.executeQuery(sqlState);
CodeAccessPermission::revertAssert();
while (resultSet.next())
{
info (int642str(resultSet.getInt64(1)));
}
Можно даже создать для этих целей отдельного пользователя на СУБД с правами только на чтение из таблицы SysClientSessions.
Способ интересный, спасибо. Но может быть есть более изящные решения?