2014-11-03 1 views
0

현재오류 SqlMapperExtension 단정를 사용하여 삽입 할 때

using (var sqlCon = new SqlConnection(Context.ReturnDatabaseConnection())) 
{ 
    sqlCon.Open(); 

    try 
    { 
     var emailExists = sqlCon.Query<UserProfile>(@"SELECT UserId FROM User_Profile WHERE EmailAddress = @EmailAddress", 
          new { EmailAddress = userRegister.EmailAddress.Trim() }).FirstOrDefault(); 

     if (emailExists == null) // No profile exists with the email passed in, so insert the new user. 
     { 
      userProfile.UniqueId = Guid.NewGuid(); 
      userProfile.Firstname = userRegister.Firstname; 
      userProfile.Surname = userRegister.Surname; 
      userProfile.EmailAddress = userRegister.EmailAddress; 
      userProfile.Username = CreateUsername(userRegister.Firstname); 
      userProfile.Password = EncryptPassword(userRegister.Password); 
      userProfile.AcceptedTerms = true; 
      userProfile.AcceptedTermsDate = System.DateTime.Now; 
      userProfile.AccountActive = true; 
      userProfile.CurrentlyOnline = true; 
      userProfile.ClosedAccountDate = null; 
      userProfile.JoinedDate = System.DateTime.Now; 

      userProfile.UserId = SqlMapperExtensions.Insert(sqlCon, userProfile); // Error on this line 

      Registration.SendWelcomeEmail(userRegister.EmailAddress, userRegister.Firstname); // Send welcome email to new user. 
     } 
    } 
    catch (Exception e) 
    { 
     Console.WriteLine(e); 
    } 
    finally 
    { 
     sqlCon.Close(); 
    } 
} 

내가 오류를 다음과 같이 내가

ExecuteNonQuery requires the command to have a transaction when the connection 
assigned to the command is in a pending local transaction. The Transaction 
property of the command has not been initialized. 

나는이 오류를 검색 좀있는 DB에 값을 삽입하기 위해 노력하고있어 단정 놀아 , 그러나 나는 대답을 오해했다.

+0

아무도 도와 드릴 수 있습니까? –

답변

0

오류 메시지에서 사용자가 커밋되거나 롤백되지 않은 트랜잭션을 시작했다고 가정합니다. 이 오류 메시지의 실제 원인은 다른 곳에 있습니다.

Context.ReturnDatabaseConnection()에 요청을 기록하고이 요청보다 먼저 어떤 요청을 추적하는지 제안합니다.

또한 모든 트랜잭션에 대한 코드를보고 올바르게 완료되었는지 (커밋/롤백) 확인하십시오.