<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Art Of Creation - Dynamics AX Blog &#187; Database</title>
	<atom:link href="http://www.artofcreation.be/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Fri, 23 Jul 2010 16:29:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Linked server sql statements</title>
		<link>http://www.artofcreation.be/2010/07/23/linked-server-sql-statements/</link>
		<comments>http://www.artofcreation.be/2010/07/23/linked-server-sql-statements/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 16:29:55 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Linked server]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=826</guid>
		<description><![CDATA[Hi all, hope you are well. Some time ago, I talked about executing direct sql statements, and now I want to share some sql statements that I used to manage linked server connections. What follows are 4 sql statements that allow you to add en remove linked servers on a database at runtime. Some assumptions: [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all, hope you are well. </p>
<p>Some time ago, I talked about <a href="http://www.artofcreation.be/2010/06/21/executing-direct-sql-statements/">executing direct sql statements</a>, and now I want to share some sql statements that I used to manage linked server connections. </p>
<p>What follows are 4 sql statements that allow you to add en remove linked servers on a database at runtime. </p>
<p>Some assumptions:<br />
- There is a str variable named &#8220;query&#8221; that will contain the query<br />
- there is a parm method on the class that return the sql server (&#8220;server&#8221; or &#8220;server\instance&#8221;)<br />
- there is a parm method that returns a username<br />
- there is a parm method that returns a password</p>
<p><strong>Check if linked server exist</strong><br />
First check if the linked server doesn&#8217;t exist yet, or you will get an error when you try to add one that already exists.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">query <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;select top 1 * from sys.servers where name = '%1'&quot;</span><span style="color: #00007f;">,</span> this.<span style="color: #000000;">parmServer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</div></div>
<p><strong>Add linked server</strong><br />
When the linked server doesn&#8217;t exist, add it.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">query <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;EXEC sp_addLinkedServer @server = '%1', @srvproduct=N'SQL Server'&quot;</span><span style="color: #00007f;">,</span> this.<span style="color: #000000;">parmServer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</div></div>
<p><strong>Add linked server login</strong><br />
Optionally, you can add a login that will be used to connect to the linked server.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">query <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;sp_addlinkedsrvlogin @rmtsrvname = '%1' ,@useself = FALSE, @locallogin = NULL, @rmtuser = '%2', @rmtpassword = '%3'&quot;</span><span style="color: #00007f;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.<span style="color: #000000;">parmServer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.<span style="color: #000000;">parmUsername</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.<span style="color: #000000;">parmPassword</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</div></div>
<p><strong>Remove linked server</strong><br />
Optionally, you can remove the linked server.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">query <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;EXEC sp_dropserver '%1', 'droplogins'&quot;</span><span style="color: #00007f;">,</span> this.<span style="color: #000000;">parmServer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/07/23/linked-server-sql-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Executing direct SQL statements</title>
		<link>http://www.artofcreation.be/2010/06/21/executing-direct-sql-statements/</link>
		<comments>http://www.artofcreation.be/2010/06/21/executing-direct-sql-statements/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 16:35:22 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Datasource]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=796</guid>
		<description><![CDATA[Hi everyone, Today I want to talk about executing SQL statements in X++ on both the AX database and external databases. This is something probably every AX developer will have to do at some point. You&#8217;ll want to do this for many reasons; to execute stored procedures, to improve performance, to get data from an [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone, </p>
<p>Today I want to talk about executing SQL statements in X++ on both the AX database and external databases. This is something probably every AX developer will have to do at some point.</p>
<p>You&#8217;ll want to do this for many reasons; to execute stored procedures, to improve performance, to get data from an external database, and so on. </p>
<p>I will provide samples for two classes:<br />
- Connection (Execute SQL statement on current AX database)<br />
- ODBCConnection (Execute SQL statement on external database)</p>
<p>I will not cover the ADO connection (CCADOConnection class), because it doesn&#8217;t work when you run it on server (or in batch), and I don&#8217;t like that. If you do, try to convince me ;-). </p>
<h3>Executing direct SQL on the current AX database</h3>
<p>When you execute a SQL statement, there are two options:<br />
- either you did a select and you expect a result to be returned<br />
- or you did insert/update/delete and you don&#8217;t expect a result. </p>
<p>The first sample is for a SQL statement that returns a result:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">server</span> <span style="color: #0000ff;">void</span> main<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Connection &nbsp; &nbsp; &nbsp;connection;<br />
&nbsp; &nbsp; Statement &nbsp; &nbsp; &nbsp; statement;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query;<br />
&nbsp; &nbsp; Resultset &nbsp; &nbsp; &nbsp; resultSet;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create connection object</span><br />
&nbsp; &nbsp; connection <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> Connection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create statement</span><br />
&nbsp; &nbsp; statement <span style="color: #00007f;">=</span> connection.<span style="color: #000000;">createStatement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// Set the SQL statement</span><br />
&nbsp; &nbsp; query <span style="color: #00007f;">=</span> <span style="color: #ff0000;">'select name from CustTable'</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// assert SQL statement execute permission</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">new</span> SqlStatementExecutePermission<span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">assert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// when the query returns result,</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// loop all results for processing</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">//BP Deviation documented</span><br />
&nbsp; &nbsp; resultSet <span style="color: #00007f;">=</span> statement.<span style="color: #000000;">executeQuery</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #000000;">&#40;</span>resultSet.<span style="color: #0000ff;">next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// do something with the result</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; info<span style="color: #000000;">&#40;</span>resultSet.<span style="color: #000000;">getString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// limit the scope of the assert call</span><br />
&nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">revertAssert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Note: this is a main method, put it in a class. Also note that it has to run on server. </p>
<p>Now if you do an update/delete/insert, you will want to do something like this:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">server</span> <span style="color: #0000ff;">void</span> main<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Connection &nbsp; &nbsp; &nbsp;connection;<br />
&nbsp; &nbsp; Statement &nbsp; &nbsp; &nbsp; statement;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create connection object</span><br />
&nbsp; &nbsp; connection <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> Connection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create statement</span><br />
&nbsp; &nbsp; statement <span style="color: #00007f;">=</span> connection.<span style="color: #000000;">createStatement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// Set the SQL statement</span><br />
&nbsp; &nbsp; query <span style="color: #00007f;">=</span> <span style="color: #ff0000;">&quot;insert into CustTable (AccountNum, Name, RecId) values ('demo', 'demo', 2)&quot;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// assert SQL statement execute permission</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">new</span> SqlStatementExecutePermission<span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">assert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">//BP Deviation documented</span><br />
&nbsp; &nbsp; statement.<span style="color: #000000;">executeUpdate</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// limit the scope of the assert call</span><br />
&nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">revertAssert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>You can find more info about the executeQuery() and executeUpdate() methods on msdn:<br />
<a href="http://msdn.microsoft.com/en-us/library/aa861335.aspx">Statement Class</a></p>
<h3>Executing direct SQL on an external database using ODBC</h3>
<p>Again, we have to differentiate between queries that return a result and those that don&#8217;t. </p>
<p>The following code sample retrieves records from an external database and processes the result:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">server</span> <span style="color: #0000ff;">void</span> main<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Statement &nbsp; &nbsp; &nbsp; statement;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query;<br />
&nbsp; &nbsp; Resultset &nbsp; &nbsp; &nbsp; resultSet;<br />
&nbsp; &nbsp; LoginProperty &nbsp; loginProperty;<br />
&nbsp; &nbsp; OdbcConnection &nbsp;odbcConnection;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; loginProperty <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> LoginProperty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; loginProperty.<span style="color: #000000;">setDSN</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'YOURDSN'</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; odbcConnection <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> OdbcConnection<span style="color: #000000;">&#40;</span>loginProperty<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// Create new Statement instance</span><br />
&nbsp; &nbsp; statement <span style="color: #00007f;">=</span>odbcConnection.<span style="color: #000000;">CreateStatement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// Set the SQL statement</span><br />
&nbsp; &nbsp; query <span style="color: #00007f;">=</span> <span style="color: #ff0000;">'select name from CustTable'</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// assert SQL statement execute permission</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">new</span> SqlStatementExecutePermission<span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">assert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// when the query returns result,</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// loop all results for processing by handler</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">//BP Deviation documented</span><br />
&nbsp; &nbsp; resultSet <span style="color: #00007f;">=</span> statement.<span style="color: #000000;">executeQuery</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #000000;">&#40;</span>resultSet.<span style="color: #0000ff;">next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// do something with the result</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; info<span style="color: #000000;">&#40;</span>resultSet.<span style="color: #000000;">getString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// limit the scope of the assert call</span><br />
&nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">revertAssert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>As you can see, the code is pretty similar. The main difference is that we are using ODBC classes, including the LoginProperty class. </p>
<p>In this example, I use a DSN (Data Source Name) that I configured on the AOS server. The DSN contains a reference to the server and database you want to connect to, and also what user credentials should be used to connect to the database. This is a lot safer than storing them in AX.<br />
If you don&#8217;t know how to create a DSN, there are plenty of <a href="http://www.google.com/search?q=create+ODBC+Data+Source+Name">tutorials on the web</a>.</p>
<p>To update/delete/update, the code is more or less the same:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">server</span> <span style="color: #0000ff;">void</span> main<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Statement &nbsp; &nbsp; &nbsp; statement;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query;<br />
&nbsp; &nbsp; LoginProperty &nbsp; loginProperty;<br />
&nbsp; &nbsp; OdbcConnection &nbsp;odbcConnection;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; loginProperty <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> LoginProperty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; loginProperty.<span style="color: #000000;">setDSN</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'YOURDSN'</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; odbcConnection <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> OdbcConnection<span style="color: #000000;">&#40;</span>loginProperty<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// Create new Statement instance</span><br />
&nbsp; &nbsp; statement <span style="color: #00007f;">=</span>odbcConnection.<span style="color: #000000;">CreateStatement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// Set the SQL statement</span><br />
&nbsp; &nbsp; query <span style="color: #00007f;">=</span> <span style="color: #ff0000;">&quot;insert into CustTable (AccountNum, Name, RecId) values ('demo', 'demo', 2)&quot;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// assert SQL statement execute permission</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">new</span> SqlStatementExecutePermission<span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">assert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// when the query returns result,</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// loop all results for processing by handler</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">//BP Deviation documented</span><br />
&nbsp; &nbsp; statement.<span style="color: #000000;">executeUpdate</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// limit the scope of the assert call</span><br />
&nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">revertAssert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>If you feel that something is missing in these examples, just ask. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/06/21/executing-direct-sql-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Normalization dilemma</title>
		<link>http://www.artofcreation.be/2010/05/29/normalization-dilemma/</link>
		<comments>http://www.artofcreation.be/2010/05/29/normalization-dilemma/#comments</comments>
		<pubDate>Fri, 28 May 2010 22:42:49 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=754</guid>
		<description><![CDATA[Hi all! I have a dilemma, and would like your opinions. The situation is that I want to add fields to an existing table (say InventTable) What would you prefer: So the question is, should I add new fields to the table (option one), or should I create a new table with the fields and [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all!</p>
<p>I have a dilemma, and would like your opinions.<br />
The situation is that I want to add fields to an existing table (say InventTable)</p>
<p>What would you prefer:<br />
<a href="http://www.artofcreation.be/wp-content/uploads/fieldortable.png"><img src="http://www.artofcreation.be/wp-content/uploads/fieldortable.png" alt="Add fields or table" title="Normalization" class="size-full wp-image-763" /></a></p>
<p>So the question is, should I add new fields to the table (option one), or should I create a new table with the fields and link to it. (option 2)  </p>
<p>Normally, option 1 is the standard way of adding extra fields to a table, but option 2 has a few advantages:</p>
<ul>
<li>You don&#8217;t need to modify the existing table</li>
<li>You&#8217;ll have less trouble with these fields when you have to upgrade AX</li>
<li>It will be easier to deploy your modifications in an AX environment that already contains modifications to the table</li>
</ul>
<p>There are also a few disadvantages I can think of:</p>
<ul>
<li>You have to join 2 tables to get the data from the new fields</li>
<li>You can&#8217;t add the new fields to fields groups on the main table (InventTable in this example)</li>
<li>On forms, you will have to add a new data source, or add display fields</li>
</ul>
<p>I would certainly go for option 1 when doing customizations for a customer, but would consider option 2 for product development. I&#8217;m in doubt. How about you? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/05/29/normalization-dilemma/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Remove duplicate key entry from a table</title>
		<link>http://www.artofcreation.be/2010/04/12/remove-duplicate-key-entry-in-a-table/</link>
		<comments>http://www.artofcreation.be/2010/04/12/remove-duplicate-key-entry-in-a-table/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 16:12:08 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Job]]></category>
		<category><![CDATA[synchronize]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=547</guid>
		<description><![CDATA[Sometimes, you can&#8217;t synchronize a table because is contains duplicate records. This can occur when you change field lengths on a extended data type for example. I’ve seen people write huge SQL statements, and even jobs that create these SQL statements to remove these duplicates from a table, but there’s actually a easy way to [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you can&#8217;t synchronize a table because is contains duplicate records. This can occur when you change field lengths on a extended data type for example. </p>
<p>I’ve seen people write huge SQL statements, and even jobs that create these SQL statements to remove these duplicates from a table, but there’s actually a easy way to do this in AX. </p>
<p>Say you have a table KLFTestDuplicates that contains duplicates, then simple run the following job to remove them.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> KLFRemoveDuplicates<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Set fieldSet <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> set<span style="color: #000000;">&#40;</span>Types<span style="color: #00007f;">::</span><span style="color: #000000;">Integer</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; DictIndex &nbsp;dictIndex <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> DictIndex<span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">tablenum</span><span style="color: #000000;">&#40;</span>KLFTestDuplicates<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">indexnum</span><span style="color: #000000;">&#40;</span>KLFTestDuplicates<span style="color: #00007f;">,</span> AUniqueIdx<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> i;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>dictIndex.<span style="color: #000000;">numberOfFields</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span>i<span style="color: #00007f;">=</span><span style="color: #000000;">1</span>;i<span style="color: #00007f;">&lt;=</span>dictIndex.<span style="color: #000000;">numberOfFields</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;i<span style="color: #00007f;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldSet.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>dictIndex.<span style="color: #000000;">field</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ReleaseUpdateDB<span style="color: #00007f;">::</span><span style="color: #000000;">indexAllowDup</span><span style="color: #000000;">&#40;</span>dictIndex<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ReleaseUpdateDB<span style="color: #00007f;">::</span><span style="color: #000000;">deleteDuplicatesUsingIds</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">tablenum</span><span style="color: #000000;">&#40;</span>KLFTestDuplicates<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> <span style="color: #000000;">0</span><span style="color: #00007f;">,</span> fieldSet<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ReleaseUpdateDB<span style="color: #00007f;">::</span><span style="color: #000000;">indexAllowNoDup</span><span style="color: #000000;">&#40;</span>dictIndex<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;done&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Remember: this is useful when developing and testing, but it will remove data from you database, so use it with caution. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/04/12/remove-duplicate-key-entry-in-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check what application and database you are connected to</title>
		<link>http://www.artofcreation.be/2010/01/04/check-what-application-and-database-you-are-connected-to/</link>
		<comments>http://www.artofcreation.be/2010/01/04/check-what-application-and-database-you-are-connected-to/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 18:27:52 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Application]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=394</guid>
		<description><![CDATA[If you want a quick way to check to what database and application folder you are connected, you can use the &#8216;Upgrade checklist&#8217; form: Administration &#8211; Setup &#8211; System &#8211; Checklists &#8211; Upgrade checklist. It shows you: - Database server - Database name - Application folder - Layers in the application]]></description>
			<content:encoded><![CDATA[<p>If you want a quick way to check to what database and application folder you are connected, you can use the &#8216;Upgrade checklist&#8217; form:</p>
<p>Administration &#8211; Setup &#8211; System &#8211; Checklists &#8211; Upgrade checklist.</p>
<p>It shows you:<br />
- Database server<br />
- Database name<br />
- Application folder<br />
- Layers in the application</p>
<div id="attachment_395" class="wp-caption aligncenter" style="width: 224px"><a href="http://www.artofcreation.be/wp-content/uploads/upgradechecklist.png"><img src="http://www.artofcreation.be/wp-content/uploads/upgradechecklist-214x300.png" alt="Upgrade Checklist" title="Upgrade Checklist" width="214" height="300" class="size-medium wp-image-395" /></a><p class="wp-caption-text">Upgrade Checklist</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/01/04/check-what-application-and-database-you-are-connected-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
