Reading a table from another db schema (C#)

Hello,

 

I have an API where I receive some data that I want to insert in a table. The problem is that the table is not in the default schema 'dbo'. The API fails because it says that it cannot find the object 'dbo.LIBRA.MBK_TABLE'. It should read only 'LIBRA.MBK_TABLE'.
 

}
       private int ExecuteInsert(string customerId, DateTime lastConnectionDate)
        {
            var select = new Select(SystemUserConnection)
                               .Column(Func.Count("RecId"))
                               .From("LIBRA.MBK_TABLE")
                               .Where("RecId").IsEqual(Column.Parameter(customerId)) as Select;
           int recordExists = select.ExecuteScalar();
            if (recordExists == 0)
            {
                var insertAccount = new Insert(SystemUserConnection)
                                        .Into("LIBRA.MBK_TABLE")
                                        .Set("RecId", Column.Parameter(customerId))
                                        .Set("LastConnectionDate", Column.Parameter(lastConnectionDate));
                int rowsAffected = insertAccount.Execute();
                if (rowsAffected == 0)
                {
                    throw new Exception("Insert failed: no rows affected.");
                }
                return rowsAffected;
            }
            return 0;
        }

I tried to put .From("LIBRA", "MBK_TABLE") and to put .SchemaName("LIBRA"), but the same error appears.

 

Is there another way of doing this?

Like 0

Like

2 comments

Perhaps you'll need to use direct SQL statements for this? You can see how to do that here: https://customerfx.com/article/executing-direct-sql-statements-in-a-process-or-configuration-web-service-in-creatio-formerly-bpmonline/

Ryan

An additional option to what Ryan proposed - create a table to which you can add data with an API and on the DB level create a trigger that will automatically insert record into the table from the needed namespace in the database.

Show all comments