You are trying to download and a manipulate a blog data type directly from SQL Server. I would rather download the blob from a .NET assembly inside AX.
Database owner says we could follow similar steps like this but we would prefer to translate this code to X++ and show the information in a AX grid where we users could apply filters and download the files directly
You can use the same classes through .NET Interop. The exact solution depends on how you read the data from the external database. I would encapsulate the whole communication with the database to a separate .NET library, rather then coding it in X++.
You can, for example, pass a binary array encoded to a Base64 string and use BinData::loadFromBase64() in AX, or you can save data to a file and pass its name to AX, or so.
If you want a more specific answer, please tell me more about how you’re going to communicate with the database and where you’re going to store the data (e.g. in AX DB, in file system, loading from the external DB every time).
The external database is linked to our AX database and we want to load the documents assigned to users every time and eventually open or download. At the moment only one document at once but we have in mind to allow multiple selections and zip all the documents.
con = new OdbcConnection(LP1);
stmt = con.createStatement();
txtSelect = ’ SELECT BDDOCS.ID_DOC,’;
txtSelect += ’ BDDOCS.OBJ_OBJECT ‘; //The data type in the external database is stored as image
txtSelect += ’ FROM BDDOCS ‘;
txtSelect += ’ WHERE BDDOCS.ID_DOC = ’ + "’" + id_doc + "’";
resultado = stmt.executequery(txtSelect);
while (resultado.next())
{
//obj_object field doc pdf database SQL
binData = new BinData();
binData.setStrData(resultado.getString(6)); //We have troubles here. Which type should be use? GetString? ,GetByte?, GetInt? GetInt64?
Collation is related to texts, not to binary data.
I think you’re making your life more difficult than needed. Use LINQ to SQL or something, so you don’t have to deal with individual bytes and such stuff. Or you may want to hire somebody to do it for you.