We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

DatabaseTableAgent, read/insert to ExtraTable and getting json from external source


I'm trying to use the DatabaseTableAgent in an Online application to work against 2 different ExtraTables. 
The flow is as follows: 
I have 1 table (y_sekvensnr) which contains a counter/number for what rows i have previously uploaded. 
I then run a Task (with a httpRequest) to get a jsonString from an external source. 
My goal is to upload/input the json-result into my other extraTable (y_import), but to simplify the example i just imput "test" for now: 

using (var dtAgent = new SuperOffice.CRM.Services.DatabaseTableAgent())
    //Get sekvensnr from Suo-table
    var soSekvensnr = dtAgent.ReadRow("y_sekvensnr", 1);
    var lastSekvensnr = SuperOffice.CRM.Globalization.CultureDataFormatter.ParseEncodedInt(soSekvensnr.Values["x_sekvensnr"]);

    JObject JsonResults = await GetJson(lastSekvensnr.ToString());

    //Update other table with a simple string "test"
    var data = new SuperOffice.CRM.Services.StringDictionary()
                            {"x_json", "test"}
    var newInsert = dtAgent.InsertRow("y_pkh_import", data);

When running this snippet it crashes on the InsertRow and I get the following exeption: 
{"Invalid URI: The format of the URI could not be determined."} 

It looks like I'm unable to use a httpClient when I am inside my using-function, if I move my GetJson to the top (and set lastsekvensnr to something random) it gives me this on ReadRow: 
{"Unable to determine version of web services!"} 

Has anyone done something similar with success and can share some tips? 
A workaround could be to do the insert/update/read through a CRMscript but i would like to avoid making this more complicated then neccessary. 


RE: DatabaseTableAgent, read/insert to ExtraTable and getting json from external source

Ok, so it seems like i figured out what my problem was. 
I had Mode=Thread set in my web.config and i found an old post from Mogensen saying this: 

Session can have several settings in NetServer config file.
Mode=Thread --> each thread has a separate session. Each thread must authenticate its session.
Mode=HttpContext --> each http context has a separate session. Each Http request must authenticate its session.
Mode=Process --> each process has a separate session. All threads within the process share the same session. 

It seems logicall that using Thread would mess up my code, hopefully this will help others who get the same 'issue' later on. 


Av: Eivind Johan Fasting 6. des 2019