[SOLVED] How to retrieve stored procedure resultset using ADO

serdarulutas
Member Posts: 50
I've been searching on internet and trying. My stored procedure seems like running I cannot catch the result set. It returns -1 records. Normally, it should retrieve 1 record. I appreciate your help.
I use 'Microsoft ActiveX Data Objects 2.8 Library'
CREATE(Conn2); //'Microsoft ActiveX Data Objects 2.8 Library'.Connection
Conn2.ConnectionString := 'PROVIDER=SQLOLEDB;Data Source=%1;Initial Catalog=%2;Trusted_Connection=Yes;' //(or the alternative below)
//Conn2.ConnectionString := 'Provider=SQLNCLI10;Server=%1;Database=%2;Trusted_Connection=yes';
Conn2.Open();
CREATE(ADOCommand2); //'Microsoft ActiveX Data Objects 2.8 Library'.Command
ADOCommand2.ActiveConnection := Conn2;
ADOCommand2.CommandText := 'MyStoredProcedure';
ADOCommand2.CommandType := 4;
ADOCommand2.CommandTimeout := 0;
ADOCommand2.Execute; //This takes time
CREATE(RecSet2); //'Microsoft ActiveX Data Objects 2.8 Library'.Recordset
RecSet2.ActiveConnection := Conn2;
RecSet2.Open(AdoCommand2);
RecSet2.movefirst;
MESSAGE('Done: (%1)',RecSet2.RecordCount);
It always show RecordCount -1. It is -1 when I execute it as "RecSet2 = ADOCommand2.Execute;" as well
Thanks
FYI: The SP must return a result set. It is not necessarily 1 records only. I need to loop through on records
I use 'Microsoft ActiveX Data Objects 2.8 Library'
CREATE(Conn2); //'Microsoft ActiveX Data Objects 2.8 Library'.Connection
Conn2.ConnectionString := 'PROVIDER=SQLOLEDB;Data Source=%1;Initial Catalog=%2;Trusted_Connection=Yes;' //(or the alternative below)
//Conn2.ConnectionString := 'Provider=SQLNCLI10;Server=%1;Database=%2;Trusted_Connection=yes';
Conn2.Open();
CREATE(ADOCommand2); //'Microsoft ActiveX Data Objects 2.8 Library'.Command
ADOCommand2.ActiveConnection := Conn2;
ADOCommand2.CommandText := 'MyStoredProcedure';
ADOCommand2.CommandType := 4;
ADOCommand2.CommandTimeout := 0;
ADOCommand2.Execute; //This takes time
CREATE(RecSet2); //'Microsoft ActiveX Data Objects 2.8 Library'.Recordset
RecSet2.ActiveConnection := Conn2;
RecSet2.Open(AdoCommand2);
RecSet2.movefirst;
MESSAGE('Done: (%1)',RecSet2.RecordCount);
It always show RecordCount -1. It is -1 when I execute it as "RecSet2 = ADOCommand2.Execute;" as well
Thanks
FYI: The SP must return a result set. It is not necessarily 1 records only. I need to loop through on records
0
Best Answer
-
Thanks for the reply. It is resolved with this:
CREATE(Conn2);
Conn2.ConnectionString := ConnString;
Conn2.Open();
CREATE(RecSet2);
RecSet2.ActiveConnection := Conn2;
RecSet2.Open('EXEC MyStoredProcedure',Conn2,1,3);
RecSet2.MoveFirst;5
Answers
-
Hey serdarulutas ,
Check out this link.
https://rockwithnav.wordpress.com/tag/call-stored-procedure-from-nav-automation/
After ADOCommand.Execute; you need to write code like this.
IF ISCLEAR(ADORecSet) THEN
CREATE(ADORecSet,FALSE,TRUE);
ADORecSet.ActiveConnection := VarActiveConnection;
ADORecSet.Open(ADOCommand);
WHILE NOT ADORecSet.EOF DO BEGIN
TextFile := FORMAT(ADORecSet.Fields.Item('File').Value);
ADORecSet.MoveNext;
END;
Message('%1',File );
File is something which your SP is returning.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Thanks for the reply. It is resolved with this:
CREATE(Conn2);
Conn2.ConnectionString := ConnString;
Conn2.Open();
CREATE(RecSet2);
RecSet2.ActiveConnection := Conn2;
RecSet2.Open('EXEC MyStoredProcedure',Conn2,1,3);
RecSet2.MoveFirst;5 -
GreatThanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0
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