Search code examples
c#sql-insertinformix

Exception when using Context.SaveChanges


I am currently learning how to interact with an external database in Visual Studios via C#.

I have a table named Notetext with a column 'Id' and a column 'Text'.

I want to insert a new line with the program, but every time the program stops at 'context.SaveChanges' and shows the error message:

IBM.Data.Db2.DB2Exception: "External component has thrown an exception."

Info: I use DBMS Informix from IBM

My current code looks like this:

namespace Notebook.Models
{
    public partial class Notetext
    {
        public int Id { get; set; }

        public string Text { get; set; }
    }
}
private void InsertIntoButton_OnClick(object sender, RoutedEventArgs e)
{
    using var context = new NotebookContext();

    // Database table Notetext
    var note = new Notetext
    {
        Id = 10,
        Text = "This is the test text",
    };

    context.Notetexts.Add(note);
    context.SaveChanges();
}

I kept changing and trying a few things, but obviously not the right ones.


Don't mind my english, not my native language.


Solution

  • After much trial and error, I finally managed to solve my problem. In fact, it was caused by an in-house requirement for the creation of a new database in our DBMS that not everyone knew existed.

    However, I'll post my solution here on Stack Overflow in case anyone else might encounter a problem like this.

    Solution:

    CREATE DATABASE name_of_db IN dbse01 WITH LOG;