Thanks a lot for your suggestions .
I ran up into a new issue .
Error :Multiple calls to CodeAccessPermission.Assert
I am running the class Run on server also the main class is server static void main but then too i am getting the error .below is my code.
static void odbcconnall(Args _args)
{
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statementproduct,statementoption,statementprdrel;
ResultSet resultset,resultsetproduct,resultsetprdoptionrel;
str sqloption,sqlupdate, criteria,sqlproduct,sqlproductrelation;
SqlStatementExecutePermission perm;
Table1 Table1;
Table2 Table2;
Table3 Table3;
;
// Set the information on the ODBC.
loginProperty = new LoginProperty();
loginProperty.setDSN(“csc”);
loginProperty.setDatabase(“cs”);
//Create a connection to external database.
odbcConnection = new OdbcConnection(loginProperty);
ttsBegin;
if (odbcConnection)
{
sqloption = “SELECT * FROM Table1”;
sqlproduct = “SELECT * FROM Tabl2”;
sqlproductrelation = “SELECT * FROM Table3”;
//Assert permission for executing the sql string.
perm = new SqlStatementExecutePermission(sqloption);
perm.assert();
//Prepare the sql statement.
statementoption = odbcConnection.createStatement();
resultSet = statementoption.executeQuery(sqloption);
// statement.executeUpdate(sql);
//product
perm = new SqlStatementExecutePermission(sqlproduct);
perm.assert();
statementproduct = odbcConnection.createStatement();
resultsetproduct = statementproduct.executeQuery(sqlproduct);
//productoptionrelation
perm = new SqlStatementExecutePermission(sqlproductrelation);
perm.assert();
statementprdrel = odbcConnection.createStatement();
resultsetprdoptionrel = statementprdrel.executeQuery(sqlproductrelation);
Table1.clear();
while (resultSet.next())
{
Table1.CompanyCode = resultSet.getString(1);
Table1.CharacteristicName = resultSet.getString(2);
Table1.CharacteristicDescription = resultset.getString(3);
Table1.DeletionIndicator = resultset.getString(4);
Table1.SystemCode = resultset.getString(5);
Table1.DateCreation = resultset.getDate(6);
// Table1.Time = resultset.getString(7);
Table1.IsOptionCreated = resultset.getBoolean(8);
Table1.Owner = resultset.getstring(9);
if(table1.validateWrite())
{
table1.insert();
sqlupdate = “UPDATE [dbo].[table2] SET [Is tab2 created] = 9”;
perm = new SqlStatementExecutePermission(sqlupdate);
// perm.assert();
sqlupdateoption = odbcConnection.createStatement();
sqlupdateoption.executeQuery(sqlupdate);
}
}
Table2.clear();
while(resultsetproduct.next())
{
Table2.Product = resultsetproduct.getString(1);
Table2.SalesOrganization = resultsetproduct.getString(2);
}
resultSet.close(); statementoption.close();
}
else
{
error(“Failed to log on to the database through ODBC.”);
}
ttsCommit;
}
the main issue is during the SQL update row .
I am using perm.assert () multiple times but if i remove that then I get "‘SqlStatementExecutePermission’ failed."
There are three tables from where I am getting the data but after getting the data I need to update the sql for each record i create in AX .
Please let me know what changes do I need to do in the code ?
I have also tried permissionSet = new Set(Types::VarString); but I dont know if this works for sql ?
Thanks a ton.