Base solution for your next web application
Open Closed

OdbcConnection issue under Dependency Injection framework #3357


User avatar
0
wcbalberta created

Hello,

I ran into an issue when an OdbcConnection couldn't be opened when the caller is created through Dependency Injection. The error message is: ERROR [58005] [IBM][CLI Driver] SQL0998N Error occurred during transaction or heuristic processing. Reason Code = "16". Subcode = "2-8004D026". SQLSTATE=58005

However, with the same connection string and everything, if the caller is created without Dependency Injection, everything is fine.

// this claimSv is created not through Dependency Injection. This works.
            var claimSv = new EcoAppService();

            // this eCOAppSv is created through Dependency Injection. This doesn't work.
            // Please note that EcoAppService implements IEcoAppService
            var eCOAppSv = Resolve<IEcoAppService>();
            Should.NotThrow(() =>
            {
                var claimant1 = claimSv.GetClaimInfo(new GetClaimInfoInput() { ClaimNumber = "4252525" });
                var claimant2 = eCOAppSv.GetClaimInfo(new GetClaimInfoInput() {ClaimNumber = "4252525"});
            });
// The connection string is to connect to a DB2 database.
            var con = new OdbcConnection(_connString);
            try
            {
                var command = con.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = GetClaimInfoQuery(claimNumber);
                // Fail right here if the caller is created through Dependency Injection.
                con.Open();

Could you please assist to make it work with Dependency Injection?

Thanks,


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you are using DB2 which I don't have any knowledge but according to this post <a class="postlink" href="http://forums.lhotka.net/forums/p/4777/52828.aspx">http://forums.lhotka.net/forums/p/4777/52828.aspx</a> it does not support System.Transactions.TransactionScope.

    If you are using this in rare places of your app, you can disable unitOfWork, see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocDisablingUow">https://aspnetboilerplate.com/Pages/Doc ... sablingUow</a>.

    If not, we may find another solution.

    Thanks.

  • User Avatar
    0
    wcbalberta created

    Disabling UnitOfWork didn't work but your reply prompted me to try TransactionScope.Suppress which ignores the current transaction. TransactionScope.Suppress totally works!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)