Can't store Data within ServiceMethod

Hi,
in my DA Project i added this ServiceMethon on the server side.

[ServiceMethod]
public AddUser(string name, string pwd)
{
	var currentConnection = this.Connection;
	var con = Engine.ConnectionManager.ConnectionDefinitions["XXXX"].ConnectionString;
	this.Connection = new BaseConnection("XXXX", con, true);

	var lda = new LinqLocalDataAdapter(this);

	try
	{
        var userlist = (from x in lda.GetTable<USER>()
            select x).ToArray();
	
		USER u = new USER
		{
			Name = name,
			Passwort = pwd
		};
			
		lda.InsertRow(u);
		lda.ApplyChangesAsync();
	}
	catch (Exception ex)
	{
		System.Diagnostics.Debug.WriteLine("Error: " + ex.Message);
	}
	finally
	{
		var actualConnection = Connection;
		Connection = currentConnection;

		if (actualConnection != null)
		{
			if (actualConnection.Connected)
			{
				actualConnection.Close();
			}
		}
	}
}

I get the userlist filled with data, but can’t insert new user. Nothing happens. There is no new user in the Database stored.

Do i miss something ?

Thanks and regards
Helmut

Hello

Seems you try to execute insert operation asynchronously nd then kill the connection it uses:

...
lda.ApplyChangesAsync();
...

Try to use this method instead:

lda.ApplyChanges();

Regards

Hello Anton,

that fixed it. My mistake. I didn’t saw it.

Regards