web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to import .mdb files(MS access DB) into AX 2009 through code

(0) ShareShare
ReportReport
Posted on by 555

Hello everyone,

I am trying to import a password protected .mdb file into ax 2009 table through code.I am able to import Excel file but i didnt find any solution to import mdb file.Can any one please suggest me whether is it possible to import .mdb file through code into AX,if possible please suggest me how to complete this requirement

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PA-22040759-0 Profile Picture
    6,194 on at
    RE: How to import .mdb files(MS access DB) into AX 2009 through code

    I take it you're on AX 2009, and thus not able to use the Data Import/Export Framework from AX 2012.

    In AX 2009 you can write code to import data through ODBC. Here is more information: https://msdn.microsoft.com/en-us/library/ee677510(v=ax.50).aspx

  • ksv1 Profile Picture
    555 on at
    RE: How to import .mdb files(MS access DB) into AX 2009 through code

    Hi Palle,

    Thanks for the reply,my requirement is that i will get .mdb (microsoft access Database)files form client,i have to import that file data into AX table .Is it possible to directly import ".mdb" file like Excel file how we import through code.                                      

  • Suggested answer
    PA-22040759-0 Profile Picture
    6,194 on at
    RE: How to import .mdb files(MS access DB) into AX 2009 through code

    There is no object model in AX for working directly with a ."mdb" file. You will need to work with it through an ODBC connection.

    The Data Import/Exporr framework in AX 2012 has a setup for working with ODBC files. Maybe you can get some inspiration for the setup there.

  • ksv1 Profile Picture
    555 on at
    RE: How to import .mdb files(MS access DB) into AX 2009 through code

    Hello Palle,

    I am able to import mdb(MS Access) file data into AX Tables using ODBC Connection,but the problem

    is before running my code i have to do setup the database name  in Control Panel ->Administrative tools->Datasources(ODBC)->DSN. Here i have to select database name i.e., mdb file name.After this if i try to import another file which was not selected in above Control panel path ,if i run the code now AX is importing the file which is in DSN but now which i have selected dialog of my code.

    My code is as follows:

    static void importmdbodbc(Args _args)

    {

       LoginProperty LP                =  new LoginProperty();

       OdbcConnection                  myConnection;

       //ableName                            TableName;

       Dialog      dialog;

       DialogField dialogfile;

       DialogField dialogpwd;

       TestImport test;

       Statement                              myStatement;

       ResultSet                                 myResult;

       str pwd,amount,recieptdate,myConnectionString;

       FileName filename;

       date d1;

       ;

       dialog              =   new Dialog("Mdb file Upoad");

       dialogfile      =   dialog.addField(typeId(FilenameOpen));

       //ialogpwd = dialog.addField(typeId(Password));

       //ialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS]);

       dialog.filenameLookupTitle("Upload from Excel");

       dialog.caption("Mdb Upload");

       dialogfile.value(filename);

       if(!dialog.run())

       return;

       filename            =   dialogfile.value();

       pwd = "bcits2005";

       #define.Constring("DSN=Xtreme Sample Database;DB=filename;Data Source =filename;PWD=yyy")//

       //define.Constring("PWD=yyy")

       //#define.Constring("DRIVER={Driver do Microsoft Access};DSN=Xtreme Sample Database1;Data Source =filename;PWD=bcits2005")

       //myConnectionString=strfmt("PWD=%1",pwd);

       //LP.setDSN("Xtreme Sample Database");

       //LP.setDatabase("filename");

       //Lp.setOther(myConnectionString);

       try

       {

       LP.setOther(#Constring);

       myConnection = new OdbcConnection(LP);

       }

       catch

       {

       info("Check username/password.");

       return;

       }

       myStatement = myConnection.createStatement();

       new SqlStatementExecutePermission("SELECT * from xxx where bImportflag = 0").assert();

       myResult = myStatement.executeQuery("SELECT * from xxx");

       CodeAccessPermission::revertAssert();

       while (myResult.next())

       {

        test.CustAccount =  myResult.getString(3);

        recieptdate      =  myResult.getString(4);

       //test.Filename    = filename;

        test.Recieptdate =  str2date(recieptdate,123);//(myResult.getString(4),123);

         amount = myResult.getString(5);

        test.Amount      =  any2real(strdel(amount,1,1));//any2real(myResult.getString(5));

        test.insert();

       //print myResult.getString(3);

        //info(strfmt("%1",myResult.getString(1)));

       }

    }

  • PA-22040759-0 Profile Picture
    6,194 on at
    RE: How to import .mdb files(MS access DB) into AX 2009 through code

    I'm not entirely sure what your problem, so forgive me if I'm going in the wrong direction.

    But, yes you need to point to a DSN. Maybe you could create these as File DSN's, so you can share them amongst boxes with the right ODBC drivers.

    And maybe you could even create the file on the fly. The files are not very complex. Here is an example of a file DSN I just made:

    [ODBC]

    DRIVER=Microsoft Access Driver (*.mdb, *.accdb)

    UID=admin

    UserCommitSync=Yes

    Threads=3

    SafeTransactions=0

    PageTimeout=5

    MaxScanRows=8

    MaxBufferSize=2048

    FIL=MS Access

    DriverId=25

    DefaultDir=C:\Users\Administrator\Documents

    DBQ=C:\Users\Administrator\Documents\Database1.accdb

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans