Question

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

0 comments
Show all comments