简体   繁体   中英

Underlying connection failed to open after TransactionScope Complete

I have an UserRegistration form which contains some particular information about the user.I want to update the form and want to intimate the user about changes via Email.The problem is after updation is complete when I try to retreive the user information(inorder to send the email) I am getting the following error.

The underlying provider failed on Open.

Here's what I have tried

 using (TransactionScope _ts = new TransactionScope())
 {
    _dbRegn = _db.StudentRegistrations.Where(r => r.Id == mdlCourseInterchange.StudentRegistration.Id)
              .FirstOrDefault();

    if(_dbRegn!=null)
    {
        //code for updating _dbRegn
        ......
        ......
        ......

        _db.Entry(_dbRegn).State = EntityState.Modified;
        int j = _db.SaveChanges();
        if (j > 0)
        {
           _ts.Complete();   

          StudentRegistration _studReg = _db.StudentRegistrations
                                         .Where(r => r.Id == _dbRegn.Id).FirstOrDefault();
           //Here I am getting the error .Cannot get latest studentregistration details
        }                               
    }
 }

Is it possible to retrieve the latest StudentRegistration details after transaction complete

Are using entity framework to access the data? Try to set user and password in connection string configuration. It was happened to me as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM