Problem with ADO.Command.ActiveConnection:=aConnection

jesam
Member Posts: 100
I have the following code in a PROCEDURE (Navision Attain 3.10) :
CREATE(aConnection);
aConnection.ConnectionString := LBGen.GetConnectionString;
aConnection.Open;
IF aConnection.State = 1 THEN BEGIN // adStateOpen = 1
CREATE(aCommand);
aCommand.ActiveConnection := aConnection;
aCommand.CommandType := 4; //adCmdStoredProc
aCommand.CommandText := 'INVInsItemLedgerEntrySummary';
aCommand.Execute;
END ELSE BEGIN
// Connection is not Open.
END;
This is the definition of the variables :
aConnection Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Connection
aCommand Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Command
The problem is that the compiler gives an error on the line :
aCommand.ActiveConnection := aConnection;
The error says : Type conversion is not possible because 1 of the operator contains an invalid type.
Integer := Automation
Can anybody explain what I have done wrong ?
CREATE(aConnection);
aConnection.ConnectionString := LBGen.GetConnectionString;
aConnection.Open;
IF aConnection.State = 1 THEN BEGIN // adStateOpen = 1
CREATE(aCommand);
aCommand.ActiveConnection := aConnection;
aCommand.CommandType := 4; //adCmdStoredProc
aCommand.CommandText := 'INVInsItemLedgerEntrySummary';
aCommand.Execute;
END ELSE BEGIN
// Connection is not Open.
END;
This is the definition of the variables :
aConnection Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Connection
aCommand Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Command
The problem is that the compiler gives an error on the line :
aCommand.ActiveConnection := aConnection;
The error says : Type conversion is not possible because 1 of the operator contains an invalid type.
Integer := Automation
Can anybody explain what I have done wrong ?
0
Comments
-
I have found why the Compiler complains, but I do not know how to fix it, so help is still welcome.
When looking at the aCommand variable through C/AL symbols, it show the following definition :
[_CONNECTION ActiveConnection :=] aCommand.ActiveConnection([BOOL ActiveConnection])
This is the root of the problem, for some reason Navision thinks that the ActiveConnection property needs to take a Bool, when in VB it clearly can accept an object of type Connection.
Does anybody know what the remedy is ?0 -
Aparrantly MS realised that there was a problem and in ADO 2.8, the Command Object has a lot of additional methods and properties so I was able to rewrite the code :
CREATE(aCommand); aCommand.ConnectionString := LBGen.GetConnectionString; aCommand.Open; IF aCommand.State = 1 THEN BEGIN //Open aCommand.Execute('exec INVInsItemLedgerEntrySummary ' + '''' + myStockFilter + ''''); END ELSE BEGIN // Connection is not Open. END; CLEAR(aCommand);
I still find it strange that there is not a single reference to find about this on the internet. I can't believe that we are the only ones that want to fire a stored procedure from Navision ...0 -
I'm trying to insert data from Navision into MS Access. I'm using the following code:
// DataConn is an Automation datatype and is a 'Microsoft ActiveX Data Objects 2.7 Library'.Connection // DataRSet is an Automation datatype and is a 'Microsoft ActiveX Data Objects 2.7 Library'.Recordset CREATE(DataConn); DataConn.ConnectionString := 'DBQ=F:\247 Deliverable\Testdb.mdb;DRIVER={Microsoft Access Driver (*.mdb)}'; CREATE(DataRSet); DataConn.Open; Window.UPDATE(1,'Customer'); strSQL := 'INSERT INTO Customer_Service_Level(Customer_No_,Service_Level_Code,Default,Service_Level_Description) '; strSQL := strSQL + 'VALUES("2464212230","2","-1","SLOW")'; RecordsAffected := ''; Options := 0; DataRSet := DataConn.Execute(strSQL,RecordsAffected,Options);
When I try to run this test, I get the error:
"The call to member Execute failed. Microsoft OLE DB Provider for ODBC Drivers returned the following message:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4."
I was doing a simple DataConn.Execute at first, but now used the empty variables RecordsAffected and Options as parameters to overcome this error. But still the error persists.
I would appreciate it if anyone could point me in the right direction.
TIA0 -
sbhamidi:
I think the problem is with the character " surrounding your values, you need to use two consecutives of the character ' instead, like:'VALUES(' '2464212230' ',' '2' ',' '-1' ',' 'SLOW' ')';
(the spaces between the ' are shown only so that my example makes some sense and should be deleted in actual code)
Please note that if you are posting to a number field in Access you do not need the delimiters at all for example:'VALUES(2464212230,2,-1,' 'SLOW' ')';
0 -
That did it!! Thanks a bunch mans.akerlaund!!0
-
This problem can be solved if you declared the variable var_aConnection as variant
var_aConnection:= aConnection;
aCommand.ActiveConnection := var_aConnection;
aCommand.CommandType := 4; //adCmdStoredProc
aCommand.CommandText := 'INVInsItemLedgerEntrySummary';
aCommand.Execute;
By this way program will be compiling and will be work !!!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