Automation variable has not been instantiated

rsaritzky
Member Posts: 469
Hello all:
I'm having a problem getting an ADO access of an external database to work. The error is:
"This message is for C/AL programmers: This Automation variable has not been instantiated. You can instantiate it by either creating or assigning it"
My NAV is a 3.60 database running under the 5.0SP1 NAV client (SQL).
I've built a test form that calls a function in a codeunit. The button on the test form executes the following:
TestCodeUnit.CheckForWorkOrder(InputField)
In my Codeunit "TestCodeUnit", the function "CheckForWorkOrder" is coded as follows. Watching the debugger, the error appears when the ADORECORDSET.OPEN command is executed:
ADOError := FALSE;
CLEAR(ADOConnection);
IF NOT CREATE(ADOConnection) THEN BEGIN
MESSAGE('Cannot connect to Work Order Database right now - problem in Codeunit 50003 creating ADO Connection automation variable.');
ADOError := TRUE;
END;
IF ADOError = FALSE THEN BEGIN
ADOConnection.ConnectionString('Provider=SQLOLEDB;' +
'Integrated Security=SSPI;' +
'Data Source=MyDatabaseName;' +
'Initial Catalog=MyCatalog;') +
'User ID=NavAppReadOnly;Password=xxxxx;');
ADOConnection.Open;
SQLString[1] := 'SELECT case_number from casetable ';
SQLString[1] += 'WHERE case_number = ''' + COPYSTR(PWorkOrderNo,1,10) + '''' ;
OpenMethod := 0;
LockMethod := 1;
ADORecSet.Open(SQLString[1],ADOConnection,OpenMethod,LockMethod); // <---Error occurs here
IF NOT ADORecSet.EOF THEN BEGIN
....<code to display info is here>....
END;
The codeunit is NOT SingleInstance.
Globals in the codeunit:
Name DataType Subtype Length
ADOConnection Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Connection
ADORecSet Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset
ADOError Boolean
Locals in the function "CheckForWorkOrder":
Name DataType Subtype Length
SQLString Text 1000
OpenMethod Integer
LockMethod Integer
Parameters in the function:
Var Name DataType Subtype Length
No PWorkOrderNo Code 20
I've tried moving all the variables to locals in the function, also moving all the variables to Globals in the function.
I don't have much experience using ADO, and haven't been able to find any references on how to "instantiate" an Automation variable.
Any suggestions?
Thanks
Ron
I'm having a problem getting an ADO access of an external database to work. The error is:
"This message is for C/AL programmers: This Automation variable has not been instantiated. You can instantiate it by either creating or assigning it"
My NAV is a 3.60 database running under the 5.0SP1 NAV client (SQL).
I've built a test form that calls a function in a codeunit. The button on the test form executes the following:
TestCodeUnit.CheckForWorkOrder(InputField)
In my Codeunit "TestCodeUnit", the function "CheckForWorkOrder" is coded as follows. Watching the debugger, the error appears when the ADORECORDSET.OPEN command is executed:
ADOError := FALSE;
CLEAR(ADOConnection);
IF NOT CREATE(ADOConnection) THEN BEGIN
MESSAGE('Cannot connect to Work Order Database right now - problem in Codeunit 50003 creating ADO Connection automation variable.');
ADOError := TRUE;
END;
IF ADOError = FALSE THEN BEGIN
ADOConnection.ConnectionString('Provider=SQLOLEDB;' +
'Integrated Security=SSPI;' +
'Data Source=MyDatabaseName;' +
'Initial Catalog=MyCatalog;') +
'User ID=NavAppReadOnly;Password=xxxxx;');
ADOConnection.Open;
SQLString[1] := 'SELECT case_number from casetable ';
SQLString[1] += 'WHERE case_number = ''' + COPYSTR(PWorkOrderNo,1,10) + '''' ;
OpenMethod := 0;
LockMethod := 1;
ADORecSet.Open(SQLString[1],ADOConnection,OpenMethod,LockMethod); // <---Error occurs here
IF NOT ADORecSet.EOF THEN BEGIN
....<code to display info is here>....
END;
The codeunit is NOT SingleInstance.
Globals in the codeunit:
Name DataType Subtype Length
ADOConnection Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Connection
ADORecSet Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset
ADOError Boolean
Locals in the function "CheckForWorkOrder":
Name DataType Subtype Length
SQLString Text 1000
OpenMethod Integer
LockMethod Integer
Parameters in the function:
Var Name DataType Subtype Length
No PWorkOrderNo Code 20
I've tried moving all the variables to locals in the function, also moving all the variables to Globals in the function.
I don't have much experience using ADO, and haven't been able to find any references on how to "instantiate" an Automation variable.
Any suggestions?
Thanks
Ron
Ron
0
Comments
-
Hi Ron,
to instantiate an automation variable is to Create it
here is some code I wrote, maybe this will help you:IF ISCLEAR(tsAdoConnection) THEN CREATE(tsAdoConnection); getConnectionString; tsAdoConnection.ConnectionString(tsConnectionString); tsAdoConnection.Open; tsCompanyName := tsCompanyInfo.Name; IF ISCLEAR(adocommand) THEN CREATE(adocommand); OpenConnection := tsAdoConnection; adocommand.ActiveConnection := OpenConnection; adocommand.CommandText := 'Select * FROM [dbo].[Table]' + 'Where [dbo].[table].[Company Name] = ' + SQ + tsCompanyName + SQ + ' And [dbo].[table].[No] = ' + SQ + tsJobNo_Param + SQ ; adocommand.CommandType := 1; adocommand.CommandTimeout := 0; adocommand.Execute; IF ISCLEAR(tsAdoRecordSet) THEN CREATE(tsAdoRecordSet); tsAdoRecordSet.ActiveConnection := OpenConnection; tsAdoRecordSet.Open(adocommand); CLEAR(tsTotalLines); CLEAR(tsLineCount); WHILE NOT tsAdoRecordSet.EOF DO BEGIN
I hope this helps you out,
Regards,
WillyFostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.0 -
You need to do a CREATE, just like you do hereIF NOT CREATE(ADOConnection) THEN BEGIN
but with the other Automation variable.0 -
matttrax wrote:You need to do a CREATE, just like you do hereIF NOT CREATE(ADOConnection) THEN BEGIN
but with the other Automation variable.
So you're saying I have to do:
CREATE(ADORecordSet)
? (see my code above)
I didn't think an automation variable of type Recordset had to be CREATE'd - but my knowledge is limited - just looked at examples here on MIBUSO and viewed some other sample code.
But I'll definitely try it - thanks!
RonRon0 -
My experience with automation is limited, but I thought you always had to create an instance of it.0
-
Well it was as simple as that - I just added a CREATE(ADORecSet) line and that took care of the error. Thanks to Mattrax and KYDutchie for responding!
RonRon0 -
I have stopped getting the error message, I re-installed the variable and although the object did not need saving, when run now, no error.
I have read the thread carefully and I think my code is solid but I am getting the same error message.
I need to check the status of the Job Queue entries and Reset them if they have stalled.
Any ideas most welcome.
OnRun()
IF ISCLEAR(autNavisionTimer) THEN BEGIN
CREATE(autNavisionTimer);
autNavisionTimer.Interval(JobQueueSetup."Check Every N Seconds" * 1000);
autNavisionTimer.Enabled(TRUE);
END;Experience is what you get when you hoped to get money0 -
Where does the error occur?
Thomas0 -
I don't get it now.
I found an answer elsewhere.
I re-inserted the timer variable and that sorted the problem.
:whistle:Experience is what you get when you hoped to get money0
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