2011-06-29 17 views
0

は、例外がスローされた場合は、最初のトランザクションがロールバックを得たが、二番目のは...2番目のトランザクションでトランザクションスコープが機能していませんか?私のアプリケーションのトランザクションスコープが第二transaction..Itのために働いていませんが、最初のトランザクションのために正常に動作しているに

public string InsertRealm(string adminuser, string adminpassword, string CustomerCode, string CustomerName, string address, string email, string phone, string NoOfUsers, string ProductType) 
{ 

    try 
    { 
    using (Transactions.TransactionScope scope = new Transactions.TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { 
     string _strServer = sqlmethod.Read_config("deploymentSetting", "Server"); 
     string _strDatabase = sqlmethod.Read_config("deploymentSetting", "database"); 
     string _strUserid = sqlmethod.Read_config("deploymentSetting", "username"); 
     string _strPassword = sqlmethod.Read_config("deploymentSetting", "password"); 
     string constr_str = "server=" + _strServer + ";" + "database=" + _strDatabase + ";" + "uid=" + _strUserid + ";" + "pwd=" + _strPassword + ";"; 

     string _blankdbCrm = sqlmethod.Read_config("dbSettings", "blankcrmdbName"); 
     string userCountdb = sqlmethod.Read_config("dbSettings", "userCountdb"); 
     string bakRestorePath = sqlmethod.Read_config("dbSettings", "bakRestorePath"); 
     string mdfRestorePath = sqlmethod.Read_config("dbSettings", "mdfRestorePath"); 
     string ldfRestorePath = sqlmethod.Read_config("dbSettings", "ldfRestorePath"); 
     string _dbCrm = ""; 

     con.ConnectionString = constr_str; 


     if (flag == "Yes") 
     { 
     SqlCommand cmddb = new SqlCommand("crt_crm_db_details", con); 
     cmddb.CommandType = CommandType.StoredProcedure; 
     cmddb.CommandTimeout = 0; 
     cmddb.Parameters.Add("@custname", SqlDbType.NVarChar).Value = ccode; 
     cmddb.Parameters.Add("@blank_dbname", SqlDbType.NVarChar).Value = _blankdbCrm; 
     cmddb.Parameters.Add("@blank_bakpath", SqlDbType.NVarChar).Value = bakRestorePath; 
     cmddb.Parameters.Add("@blank_mdfpath", SqlDbType.NVarChar).Value = mdfRestorePath; 
     cmddb.Parameters.Add("@blank_ldfpath", SqlDbType.NVarChar).Value = ldfRestorePath; 
     cmddb.Parameters.Add("@usercnt", SqlDbType.NVarChar).Value = userCountdb; 

     SqlParameter Typedb = new SqlParameter("@errorid", SqlDbType.NVarChar); 
     Typedb.Direction = ParameterDirection.Output; 
     Typedb.Value = null; 
     Typedb.Size = 50; 
     cmddb.Parameters.Add(Typedb); 
     try 
     { 
      con.Open(); 
      cmddb.ExecuteNonQuery(); 
     } 
     catch (SqlException ee) 
     { 
      VWLogger.LogMessage("Exception in crt_crm_db_details:", TraceEventType.Critical); 
      VWLogger.LogMessage(ee, TraceEventType.Critical); 
      return ee.Message; 
      flag = ee.Errors(0).ToString(); 
     } 
     con.Close(); 
     } 

     if (flag == "Yes") 
     { 
     Ramco.VW.Types.Message[] Msg_cust = null; 
     try 
     { 
      Msg_cust = client.addCustomer(ccode, cname, add1, "", mail); 
     } 
     catch (SqlException ex) 
     { 
      VWLogger.LogMessage("Exception in addCustomer:", TraceEventType.Critical); 
      VWLogger.LogMessage(ex, TraceEventType.Critical); 
      return ex.Message; 
      flag = ex.Errors(0).ToString(); 
     } 
     } 

     scope.Complete(); 
     return "Success"; 
    } 

    } 
    catch (Exception ex) 
    { 
    VWLogger.LogMessage("Exception in insertrealm:", TraceEventType.Critical); 
    VWLogger.LogMessage(ex, TraceEventType.Critical); 
    return ex.Message; 
    throw new CustomSoapException(CustomSoapException.ExceptionCode.AuthenticationException, ex.Message); 
    } 

} 
ここ

cmddb.ExecuteNonQuery()なかった意味しますロールバックされていますが、この1つです

Msg_cust = client.addCustomer(ccode, cname, add1, "", mail) 

ロールバックされませんでした。

EDIT:必須が存在する場合、データベースアクセスコードが既存のトランザクションに参加することを指定し

<bindings> 
     <basicHttpBinding> 
     <binding name="UserNameTokenOverSSLBinding"> 
      <security mode="TransportWithMessageCredential" /> 
     </binding> 
     <binding name="BinaryCertTokenOverSSLBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00"> 
      <security mode="TransportWithMessageCredential"> 
      <message clientCredentialType="Certificate" /> 
      </security> 
     </binding> 
     <binding name="Vw30BasicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="65536" maxReceivedMessageSize="65536"> 
      <security> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
     <customBinding> 
      <binding name="Vw30netTcpHABinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"> 
      <binaryMessageEncoding> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      </binaryMessageEncoding> 
      <tcpTransport maxBufferPoolSize="524288" maxReceivedMessageSize="99999998" connectionBufferSize="8192" hostNameComparisonMode="StrongWildcard" channelInitializationTimeout="00:01:00" maxBufferSize="99999998" maxPendingConnections="20" maxOutputDelay="00:00:00.2000000" maxPendingAccepts="5" transferMode="Buffered" listenBacklog="20" portSharingEnabled="false" teredoEnabled="false"> 
      <connectionPoolSettings groupName="default" leaseTimeout="00:00:02" idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" /> 
      </tcpTransport> 
      </binding> 
      <binding name="Vw30HttpHABinding"> 
      <textMessageEncoding /> 
      <httpTransport keepAliveEnabled="false"> 
      </httpTransport> 
     </binding> 

     <binding name="UserNameTokenOverSSLOffloaderBinding"> 
      <textMessageEncoding messageVersion="Soap11" /> 
      <security authenticationMode="UserNameOverTransport"> 
      <secureConversationBootstrap /> 
      </security> 
      <sslOffloadedHttpsTransport /> 
     </binding> 
     <binding name="BinaryCertTokenOverSSLOffloaderBinding"> 
      <textMessageEncoding messageVersion="Soap11" /> 
      <security authenticationMode="UserNameOverTransport"> 
      <secureConversationBootstrap /> 
      </security> 
      <sslOffloadedHttpsTransport /> 
     </binding> 
     </customBinding> 
     <netTcpBinding> 
     <binding name="Vw30netTcpBinding" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" protectionLevel="None" /> 
      <message clientCredentialType="None" /> 
      </security> 
     </binding> 
     </netTcpBinding> 
     <wsHttpBinding> 
     <binding name="WSUserNameBinding" transactionFlow="true"> 
      <security> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="false" /> 
      </security> 
     </binding> 
     <binding name="WSBinaryCertBinding" transactionFlow="true"> 
      <security> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="Certificate" negotiateServiceCredential="false" establishSecurityContext="false" /> 
      </security> 
     </binding> 
     <binding name="WSUserNameReliableBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="true"> 
      <reliableSession enabled="true" /> 
      <security> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName" negotiateServiceCredential="false" /> 
      </security> 
     </binding> 
     <binding name="WsBinaryCertReliableBinding" transactionFlow="true"> 
      <reliableSession enabled="true" /> 
      <security> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="Certificate" negotiateServiceCredential="false" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
+0

'client'は何ですか? Webサービスコールのように見えますが、もちろんトランザクションスコープはそこには適用されません。 –

+0

ya..its webservice calls .. – bala3569

+0

でも、ロールバックする必要があります。何をすればいいですか。 – bala3569

答えて

2

あなたはどの種類のWebサービスを呼び出していますか、それを制御できますか?

これはWCF Webサービスであり、編集が可能であれば、WCF Transaction Flowを使用して、クライアントからのトランザクションを制御できます。基本的に、TransactionScopeは分散トランザクションになり、WCF Webサービスに引き継がれます。あなたのトランザクションは適切にロールバックされます。

さらに詳しい情報:

Enabling Transaction Flow (MSDN)

WCF Transaction Propagation (MSDN)

+0

これ。以下も参照してください。http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.transactionoption(v=VS.100).aspx – Godeke

+0

これは新しいです。 wcf webserviceまたはasp.net webservice..itはばかげているかもしれませんが、方法はありません – bala3569

+0

私のwebconfigで私はを持っていますので、私のWCF Webサービスは正しいのですか? – bala3569

0

トランザクションスコープオプション。最初のトランザクションがロールバックされても2番目のトランザクションをコミットする場合は、RequiresNewを指定する必要があります。

+0

いいえ、すべてをロールバックする必要はありません。 – bala3569

+0

@ bala3569:私の間違い!同じデータベースで2つのトランザクションについて話していると思いました。分散トランザクションを実装しようとしているようです。 – Olaf

0

Webサービスは、別のマシン(別のスレッド)で実行されます(可能性があります)。 TransactionScopeはスレッドベースです。現在のスレッドに対して登録されている現在のトランザクションに基づいて動作します。したがって、Webサービスコールの作成時にこの機能を使用する方法はありません。

+0

しかし、私は.svcファイルを使用してプロキシを作成し、VWSecurityServicesClientクライアント=新しいVWSecurityServicesClient( "WSBinaryCert")のようなクライアントを宣言しました。 – bala3569

+0

あなたはプロキシを作成して何をしているのですか?コードはまだ別のアプリドメイン(またはホスト!)で実行されています。 Webサービスがインターネット上の他の場所で動作している可能性があります。 (あなたがcertsを使用しているとしたら、多分そうかもしれません)あなたのマシン上のトランザクションにはどうやって参加できますか? –

+0

私の編集を見て – bala3569

関連する問題