This topic is locked
[SOLVED]

Strange error using database API (DB.Insert)

7/1/2021 5:26:59 PM
ASPRunner.NET General questions
Pete K author

In updating older apps, I'm trying to upgrade any depicated code, which includes replacing old DAL code with newer database API calls. So I tried replacing the code below, but the code generates an error:

Invalid object name '_activityLog'.

Here's the old code, which still works:

dynamic LT = GlobalVars.dal.Table("_activityLog");
LT.Value["EntryType"] = EntryType;
LT.Value["VariableName"] = VariableName;
LT.Value["EntryText"] = EntryText;
LT.Add();

Here's the new code, adapted from sample code in the help file:

dynamic data = XVar.Array();
data["EntryType"]=EntryType;
data["VariableName"]=VariableName;
data["EntryText"]=EntryText;
DB.Insert("_activityLog", data);

What did I do wrong?

Sergey Kornilov admin 7/1/2021

Maybe try this just in case:

DB.Insert("dbo._activityLog", data);

Pete K author 7/2/2021

Thanks for the suggestion. I did try that, but still got the error.

Sergey Kornilov admin 7/2/2021

Thank you. The error message still confuses me. Do you have multiple databases connections in this project?

Pete K author 7/16/2021

Yes, and that must be the issue. I'm not used to working with multiple connections so it didn't occur to me to set the connection before attmpting the insert. Thanks for the follow-up question!