Hi Experts,
I have created a new DB in SQL Server named it as temp. I need to read and write data the DB from D365fo. For that i have followed the below link.
https://docs.microsoft.com/en-us/dynamicsax-2012/developer/how-to-connect-to-an-external-database-from-x-code.
for creating DSN, I have followed this https://kb.blackbaud.com/articles/Article/41081.
I am facing issue at the odbcConnection = new OdbcConnection(loginProperty);
I have mention my code below.
public static void main(Args _args)
{
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql, criteria;
SqlStatementExecutePermission perm;
loginProperty = new LoginProperty();
loginProperty.setDSN("DSN Name");
loginProperty.setDatabase("Database");
odbcConnection = new OdbcConnection(loginProperty);
if(odbcConnection)
{
sql = "SELECT * FROM MyTable WHERE FIELD = "
criteria
" ORDER BY FIELD1, FIELD2 ASC ;";
//Assert permission for executing the sql string.
perm = new SqlStatementExecutePermission(sql);
perm.assert();
//Prepare the sql statement.
statement = odbcConnection.createStatement();
resultSet = statement.executeQuery(sql);
//Cause the sql statement to run,
//then loop through each row in the result.
while (resultSet.next())
{
//It is not possible to get field 3 and then 1.
//Always get fields in numerical order, such as 1 then 2 the 3 etc.
print resultSet.getString(1);
print resultSet.getString(3);
}
//Close the connection.
resultSet.close();
statement.close();
info(strFmt("Connection is established"));
}
else
{
Error("Failed to login to database through ODBC");
}
I have tried creating DSN with Sql server and Sql server native client 11.0 drivers but i am getting an exception like "login failed for user".
Can anyone guide me the correct path or any links to succeed the connection.
Thanks in advance.
with regards,
srihari.