Using ADO to kick-off SQL jobs from NAV

bbrown
Member Posts: 3,268
The sample code below is an example of how ADO can be used to kick-off a SQL Agent job from NAV. This can be helpful when you need to run things but they don't fit into a fixed schedule. This particular code is called from Adjust Cost, but I'm sure there are other uses. It allows us to run nightly SQL maintenance following the completion of Adjust Cost.
Name DataType Subtype Length ADOConnection Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Connection GLSetup Record General Ledger Setup ADOCommand Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Command ADOParameter Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Parameter lvarActiveConnection Variant OnRun() IF ISCLEAR(ADOConnection) THEN; CREATE(ADOConnection); ADOConnection.ConnectionString := GetConnectionString; ADOConnection.Open; IF ISCLEAR(ADOCommand) THEN CREATE(ADOCommand); lvarActiveConnection := ADOConnection; ADOCommand.ActiveConnection := lvarActiveConnection; ADOCommand.CommandText := 'sp_start_job'; ADOCommand.CommandType := 4; ADOCommand.CommandTimeout := 0; ADOParameter := ADOCommand.CreateParameter('@job_name', 200, 1, 50, GLSetup."Index Job Name"); ADOCommand.Parameters.Append(ADOParameter); ADOCommand.Execute; ADOConnection.Close; --------------------- GetConnectionString() : Text[1024] GLSetup.GET; GLSetup.TESTFIELD("Server Name"); GLSetup.TESTFIELD("Index Job Name"); ConnectString := 'Driver={SQL Native Client};' + 'Server=' + GLSetup."Server Name" + ';' + 'Database=msdb;Trusted_Connection=yes;'; EXIT(ConnectString);
There are no bugs - only undocumented features.
0
Comments
-
I have blogged about the other way around using SQL Agent jobs schedule to run NAV jobs.
Here is the link
http://mibuso.com/blogs/ara3n/2009/11/1 ... b-service/0 -
Thanks to both of you.
I am in a tuning project right now, and trying to decide between one of these approaches, your posts will make it easier for me to review both options.
Thanks.David Singleton0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions