<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="https://www.schweda.net/style_feed.css" ?>
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:atom="http://www.w3.org/2005/Atom"	
	xmlns:dc="http://purl.org/dc/elements/1.1/" > 
<channel>
    <title>schweda.net - Blog</title>
    <link>https://www.schweda.net/</link>
    <description>schweda.net - Blog - Blog-Beitraege</description>
    <language>de-at</language>
    <copyright>Copyright 2006-2026</copyright>
    <generator>schweda.net</generator>
    <managingEditor>heinz.schweda@schweda.net (Heinz Schweda)</managingEditor>
    <webMaster>heinz.schweda@schweda.net (Heinz Schweda)</webMaster>
    <category>Blog</category>
	<atom:link href="https://www.schweda.net/blog_rss.php?bid=496" rel="self" type="application/rss+xml" />
<item>
<title><![CDATA[Zugriff auf externe Datenbank via ODBC]]></title>
<description><![CDATA[
<p>Im folgenden ein paar Code-Beispiele wie man aus Dynamics AX heraus auf externe Datenbanken lesend und schreibend zugreifen kann.
</p>


<p>Die Beispiele basieren auf folgendem MSDN-Beitrag:<br />
<a href="http://msdn.microsoft.com/en-us/library/ee677510.aspx" target="_blank">How to: Connect to an External Database from X++ Code [AX 2012]</a><br />
&nbsp;
</p>


<h2>Lesender Zugriff (SELECT)
</h2>


<pre class="pre_blog_axcode">
// X++, Main method in a class.
static public void Main(Args _args)
{
    LoginProperty loginProperty;
    OdbcConnection odbcConnection;
    Statement statement;
    ResultSet resultSet;
    str sql, criteria;
    SqlStatementExecutePermission perm;
    ;

    // Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setDSN(&quot;ExternalDB_32bit&quot;);
    loginProperty.setDatabase(&quot;ExternalDatabaseName&quot;);

    //Create a connection to external database.
    odbcConnection = new OdbcConnection(loginProperty);

    if (odbcConnection)
    {
        sql = &quot;SELECT * FROM items;&quot;;

        //Assert permission for executing the sql string.
        perm = new SqlStatementExecutePermission(sql);
        perm.assert();

        //Prepare the sql statement.
        statement = odbcConnection.createStatement();
        resultSet = statement.executeQuery(sql);

        //Cause the sql statement to run,
        //then loop through each row in the result.
        while (resultSet.next())
        {
            //It is not possible to get field 3 and then 1.
            //Always get fields in numerical order, such as 1 then 2 the 3 etc.
            print strFmt(&quot;%1 - %2&quot;, strRTrim(resultSet.getString(1)), strRTrim(resultSet.getString(2)));
        }

        //Close the connection.
        resultSet.close();
        statement.close();
    }
    else
    {
        error(&quot;Failed to log on to the database through ODBC.&quot;);
    }
}
</pre>

<br /><a class="div_blog_category_gotodetail" href="https://www.schweda.net/blog_ax.php?bid=496" target="_self" title="Weiterlesen...">Weiterlesen...</a>]]></description>
<category>Microsoft Dynamics AX (Axapta)</category>
<pubDate>Sun, 02 Mar 2014 17:08:00 +0100</pubDate>
<link>https://www.schweda.net/blog_ax.php?bid=496</link>
<comments>https://www.schweda.net/blog_ax.php?bid=496</comments>
<guid isPermaLink="true">https://www.schweda.net/blog_ax.php?bid=496</guid>
<author>heinz.schweda@schweda.net (Heinz Schweda)</author>
<wfw:commentRss>https://www.schweda.net/blog_ax.php?bid=496</wfw:commentRss>
</item>
</channel>
</rss>	
