I am writing a code in AX 2012 to connect to external DB without creating Data Source Name(DSN) by just passing severName, DBName, UserID, Password. How i can pass connection string to execute this code.
Please share it how can i connect to external DB by X++ code.
How do you want to communicate with the external DB? You can, for example, create a VS project and use LINQ to SQL. In such a case, pass the connection string to data context’s constructor. SqlConnectionStringBuilder will help you to easily prepare connection strings.
I used this approach recently and it worked extremely well.
I have written this code to connect to external DB in X++ editor with connection string as credential for this connectivity but it is throwing error which i highlighted at bottom.
mySQLStatement=“SELECT * FROM CustTable”;
sqlPermission = new SQLStatementExecutePermission(mySQLStatement);
sqlPermission.assert();
myResultSet=myStatement.executeQuery(mySQLStatement);
while (myResultSet.next())
{
info(strFmt("%1, %2", myResultSet.getString(1), myResultSet.getString(4)));
//info(int2str(myResultSet.getInt(2)));
}
CodeAccessPermission::revertAssert();
} catch
{
error(‘Unexpected error’);
}
}
Where i can make changes to make it workable.?
THSI CODE IS NOT BRING VALUE FROM CUSTTABLE AND SHOWING THE ERROE LIKE THAT—"[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user ‘BWCINC\Jatul’" LIKE THAT".
PLEAE REPLY FOR IT AS SOON AS POSSIBLE.
As I said, I guess that your code doesn’t work because the only allowed authentication is via Active Directory (Windows authentication), therefore you can’t use login/password (SQL authentication). Do you say that you checked configuration of your SQL Server and SQL authentication is allowed?
I have exactly the same problem. I can connect directly from DataSource ODBC. But when I use the same settings(server name, dabase name, UID and password) through AX2012, I can not connect. I receive error like mentioned above.
Below you have Microsoft’s answer why you can not connect using ODBC and user and password(in AX 2012 as well). In such cases, instead of ODBC, I use OLE DB with success. Write, if you want some sample, how to use OLE DB. Alhough, there are many samples on websites.
This is official Microsoft’'s answer:
Resolution
Problem was escalated to escalation engineers where we confirmed the behavior of the application.
In AX 4.0 for the LoginProperty class, we had two properties on this class – setUsername & setPassword – these were the properties you used if you wanted to change the login, see link below… http://msdn.microsoft.com/en-us/library/aa623556(v=ax.10).aspx
I have looked at the kernel code, and in AX 4.0 and before if you specified the setUsername and setPassword then the kernel would use these to create the ODBC connection. If they were not specified, then they would use the login for the AX AOS service (or with AX 3.0 or before the client login in two tier mode).
So as it is no longer possible to set these properties from AX 2009 onwards, the kernel will always use the login for the AOS service. So even if you try and set these in the “setOther” property on the LoginProperty class, they are ignored as in the connection string we create in the kernel code is always using trusted authentication of the AOS Service account – so these additional properties are ignored.
Now I know why it takes my user from windows! I was thinking that my code was wrong! I will do the OLE DB connection, but I can’t find an example, could you please provide me a link or the steps to do that in AX 2012???
I can connect to an external database, but in the database I have fields that are floats and datetime. I need to convert it to real and date but I can’t.
I use datetime2date function and it doesn’t work, I need to convert all this fields to put it into a table in AX, can somebody help me?
I tried the aValue for real fields in AX and it works, thanks a lot!!! But when I try to get the date, I can’t, it sends me an error message. Do you have another example of that???