Connecting to External Database From Axapta by x++ code.Following code works fine. I tried it.

 CCADOConnection connection; 
    CCADOCommand    Cmd; 
    CCADORecordSet  RS; 
    CCADOFields     fields; 
    Com             Coms; 
    Str             Sql; 
    Str             Provider    = "testServer"; 
    Str             DataBase    = "Testdb"; 
    Str             UserId      = "abc"; 
    Str             PWD         = "xyz"; 
    Str             ConnStr = strfmt("Provider=SqlOledb;server=" + 
Provider + ";trusted_Connection=false;" + 
                                        "Initial catalog=" + DataBase + 
";user id=" + userid + ";password='" + PWD + "';"); 

    ; 
    Sql = "Select * from InventTable where itemid="10001""; 

    connection = new CCADOConnection(); 
    connection.open(ConnStr); 

    Cmd = new CCADOCommand(); 
    Cmd.activeConnection(connection); 
    Cmd.commandText(sql); 

    RS = new CCADORecordSet(); 
    RS = Cmd.execute(); 
    Coms = RS.recordSet(); 

    while (!RS.EOF()) 
    { 
        fields = RS.fields(); 
        info(strfmt("%1", fields.itemIdx(0).value())); 

        Coms.moveNext(); 
    } 

    connection.close(); 
    connection = null; 

1 comment:

  1. esto es para la version 2009, pero para las 2012?

    ReplyDelete

Note: Only a member of this blog may post a comment.