Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How connect to an External Database from X++?

2,573 views
Skip to first unread message

Kevin

unread,
Mar 15, 2010, 2:33:01 AM3/15/10
to
Hi everybody:

how connect to an external database from x++ in Ax2009?

I know use DSN, but DSN can't save database's password,

who can help me?

Jeganeedhi

unread,
Mar 15, 2010, 2:54:01 AM3/15/10
to
Kevin,

You can use ADO connection.

Ashokbau

unread,
Mar 15, 2010, 3:40:01 AM3/15/10
to

"Kevin" wrote:

> CCADOConnection connection;
CCADOCommand command;
CCADORecordSet recordSet;
CCADOFields fields;

str provider = "va";
str database = "copal";
str connectionString = strfmt("Provider=sqloledb;Data
Source=%1;Initial Catalog=%2;Trusted_Connection=yes;", provider, database);
//str statement = "exce
[dbo].[PaySp_UpdEmpDetails_FromOtherDB_ash],'AXDB'";
str statement = "EXEC GetSalesName 'ANISH'";

;

connection = new CCADOConnection();
connection.open(connectionString, #adConnectUnspecified);

command = new CCADOCommand();
command.activeConnection(connection);
command.commandText(statement);
recordSet = command.execute();

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

connection.close();
connection = null;
}

Klaas Deforche

unread,
Mar 15, 2010, 5:52:01 AM3/15/10
to
Hi,

Something you need to know about ADO: the classes run on client (runon
property), so it won't work in batch.

Use oledb instead if you want it to be able to run in batch:
http://dynamics-ax.blogspot.com/2005/11/connecting-to-database-via-odbc.html

Best regards,
Klaas.
----------------
http://www.artofcreation.be

Kevin

unread,
Mar 16, 2010, 7:13:02 AM3/16/10
to
thanks Ashokbau,

modified your code run success,
my code like this:

void Fun_OpenExternalDB()
{


CCADOConnection connection;
CCADOCommand command;
CCADORecordSet recordSet;
CCADOFields fields;

Com Coms;
Str Sql;
Str Provider = "ServerName";
Str DataBase = "DataBaseName";
Str UserId = "UserId";
Str PWD = "PWD";
Str ConnectionString = strfmt("Provider=SqlOledb;server=" +
Provider + ";trusted_Connection=false;" +
"Initial catalog=" + DataBase +
";user id=" + userid + ";password='" + PWD + "';");

;
Sql = "Select top 10 ItemId, ItemGroupId from InventTable";

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

command = new CCADOCommand();
command.activeConnection(connection);

command.commandText(sql);

recordSet = new CCADORecordSet();
recordSet = command.execute();
Coms = recordSet.recordSet();

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

Coms.moveNext();
}

connection.close();
connection = null;

Sarat

unread,
Apr 22, 2010, 10:35:01 PM4/22/10
to
Hi Kevin,
i would like to connect external database(oracle) through the ODBC driver
in Axapta 2009 X++. in the login property, the setUsername & setPassword
funtions are not aviable. please give me the any code sample for ODBC
connection in Ax 2009 X++.


Thanks && Regards
chandru R

vasantharivali

unread,
May 21, 2010, 1:29:53 AM5/21/10
to
Hi,

I connect sql server db(not a default one it is a another db) from Dynamics Axapta 2009.
I used odbc to connect and retrive data.

It was work fine in the server.
but when i was woked in ax client it show an error like this:

1) ODBC operation failed.Unable to log on to the database.

2) [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'ASCENDERS\vasanth'.

3)Object 'OdbcConnection' could not be created


i am also given the user name as sqlserver username "sa" but it take my window authentication.
i don't know how to solve the problem.plz help me with your valuable ideas..

Thanks in advance

Vasanth.A

Kevin wrote:

thanks Ashokbau,modified your code run success,my code like this:void
16-Mar-10

thanks Ashokbau,

Coms.moveNext();
}

connection.close();
connection = null;
}

"Ashokbau" wrote:

Previous Posts In This Thread:

On Monday, March 15, 2010 2:33 AM
Kevin wrote:

How connect to an External Database from X++?
Hi everybody:

how connect to an external database from x++ in Ax2009?

I know use DSN, but DSN cannot save database's password,

who can help me?

On Monday, March 15, 2010 2:54 AM
Jeganeedhi wrote:

Kevin,You can use ADO connection."Kevin" wrote:
Kevin,

You can use ADO connection.

"Kevin" wrote:

On Monday, March 15, 2010 3:40 AM
Ashokbau wrote:

"Kevin" wrote:CCADOCommand command;CCADORecordSet recordSet;CCADOFields
"Kevin" wrote:


CCADOCommand command;
CCADORecordSet recordSet;
CCADOFields fields;

str provider = "va";
str database = "copal";
str connectionString = strfmt("Provider=sqloledb;Data
Source=%1;Initial Catalog=%2;Trusted_Connection=yes;", provider, database);
//str statement = "exce
[dbo].[PaySp_UpdEmpDetails_FromOtherDB_ash],'AXDB'";
str statement = "EXEC GetSalesName 'ANISH'";

;

connection = new CCADOConnection();
connection.open(connectionString, #adConnectUnspecified);

command = new CCADOCommand();
command.activeConnection(connection);
command.commandText(statement);
recordSet = command.execute();

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

connection.close();
connection = null;
}

On Monday, March 15, 2010 5:52 AM
Klaas Deforche wrote:

Hi,Something you need to know about ADO: the classes run on client
Hi,

Something you need to know about ADO: the classes run on client (runon

property), so it will not work in batch.

Use oledb instead if you want it to be able to run in batch:
http://dynamics-ax.blogspot.com/2005/11/connecting-to-database-via-odbc.html

Best regards,
Klaas.
----------------
http://www.artofcreation.be


"Jeganeedhi" wrote:

On Tuesday, March 16, 2010 7:13 AM
Kevin wrote:

thanks Ashokbau,modified your code run success,my code like this:void
thanks Ashokbau,

Coms.moveNext();
}

connection.close();
connection = null;
}

"Ashokbau" wrote:

On Thursday, April 22, 2010 10:35 PM
Sarat wrote:

Hi Kevin,i would like to connect external database(oracle) through the ODBC


Hi Kevin,
i would like to connect external database(oracle) through the ODBC driver
in Axapta 2009 X++. in the login property, the setUsername & setPassword
funtions are not aviable. please give me the any code sample for ODBC
connection in Ax 2009 X++.


Thanks && Regards
chandru R

"Kevin" wrote:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Parallel Programming in C# 4.0: A Short Synopsis
http://www.eggheadcafe.com/tutorials/aspnet/047afdf6-61ab-4b85-9204-b0f20bdc955a/parallel-programming-in-c.aspx

0 new messages