Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Thursday, January 05, 2006

Execute a DTS package from X++

Recently someone asked how to execute a DTS package from X++. This was a great question and great timing because I had just recently completed a project that had to execute a DTS package. Below is the code that will allow you to do this:

protected void runDTSpkg()
{
OdbcConnection cn;
ResultSet rs;
Statement s;
str SQL;
str temp;
;

// Open up a connection to the Master Database, and execute the DTS package
cn = this.CN("master");
s = cn.createStatement();
SQL = "xp_cmdshell 'dtsrun /SVSQL /Usomeuser /Pblocked /NPumpOverCS_SHIP'";
rs = s.executeQuery(SQL);
while(rs.next())
{
// Here you could see if an error occurs, or just use this loop to allow the DTS to finsih.
temp = rs.getString(1);
MMI_ErrLog::logError("PkgScoop",strfmt("%1",temp));
}
}

So there are a couple of things I want to point out here. One is the actual statement used to do this:

xp_cmdshell 'dtsrun /SVSQL /Usomeuser /Pblocked /NPumpOverCS_SHIP'
The /S = Server Name, /U = User Name, /P = Password /N = Name of DTS package to execute. Notice that the parms are ran together with what your passing. This Must happen or you get an error.

Another thing I wanted to point out was that I do a while(rs.next()) {...} for the resultset. When executing a DTS package through the stored procedure xp_cmdshell results are returned telling you about what is going on. You can read these results and act on them, or do like I do and just put them into a general log table. Whatever you do though, you must preform the while(rs.next()) {...} so you can allow the DTS to fully finish before you continue to your next block of code that I assume would operate on the data that the DTS package brought in / manipulated, etc.

Well Check back soon for more handy tips and tricks!

Find a job at: www.DynamicsAXJobs.com

1 Comments:

Anonymous Anonymous said...

Can I Create DTS Package from Syntax X++??if Can, how about the syntax??

8:29 PM  

Post a Comment

Links to this post:

Create a Link

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved