Our support engineers have assembled the top recommended solutions for you.
Microsoft Dynamics AX 2012CRM Connector in Microsoft Dynamics AX 2012Financials Management in Microsoft Dynamics AX 2012Upgrading to Microsoft Dynamics AX 2012
Microsoft Dynamics AX 2009
Application Object Server (AOS)
Enterprise Portal and Role Centers
Inventory Costing in Microsoft Dynamics AX 2009
Invoice Settlements/Discounts/Reversals
SSRS and SSAS Integration
Workflow
i am trying to insert data using .net business connector but i am some facing problem with exception message "Error encountered: Cannot access a disposed object.". I am unable to grasp that what's the matter. Can anybody help me please. Thanks in advance. here is the code i am using. it is to be mentioned that i read this code from Microsoft msdn online library for Dynamics Ax. I have also included reference Microsoft.Dynamics.BusinessConnectorNet. here is the code.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Dynamics.BusinessConnectorNet;namespace ConsoleApplication2{ class Program { static void Main(string[] args) { // Create the .NET Business Connector objects. Axapta ax; AxaptaRecord axRecord; string tableName = "AddressState"; try { // Login to Microsoft Dynamics AX. ax = new Axapta(); ax.Logon(null, null, null, null); // Create a new AddressState table record. using (axRecord = ax.CreateAxaptaRecord(tableName)) ; { // Provide values for each of the AddressState record fields. axRecord.set_Field("NAME", "MyState"); axRecord.set_Field("STATEID", "MyState"); axRecord.set_Field("COUNTRYREGIONID", "US"); axRecord.set_Field("INTRASTATCODE", ""); // Commit the record to the database. axRecord.Insert(); ax.Logoff(); Console.WriteLine("Inserted Successfully"); Console.ReadLine(); } } catch (Exception e) { Console.WriteLine("Error encountered: {0}", e.Message); Console.ReadLine(); // Take other error action as needed. } } }}
Perhaps you should try to move
ax.Logoff();
to somewhere outside ths "using clause". I am not sure, but if you are logged off when disposing the record (happens when you exit using), this might occur.
/Jonas
Thanks for reply. But its not working i.e. ax.Logoff();
Ok, so this is the line that throws the exception:
??
Found the error. You have an extra ; in the code.
using (axRecord = ax.CreateAxaptaRecord(tableName)) ;
should be
using (axRecord = ax.CreateAxaptaRecord(tableName))
Now you create and dispose the object in the same line... :-)
Thanks Man!
Its working Now.
this was exactly, going wrong as you pointed