2009-05-26 10 views
1

次のコードは通常SQLSERVERで実行されますが、loadbykeyの後にmySQLで実行するようにweb.configを変更すると、接続が閉じられます。SUBSONIC MYSQL SharedDbConnectionScope TransactionScope

それを変更するにはMySQLで作る任意の構成があります?

ありがとうございました!

//----------------------------------------------------------- 
    string tipoBanco = System.Configuration.ConfigurationManager.AppSettings["tipoBanco"]; 
    string conexao = System.Configuration.ConfigurationManager.ConnectionStrings[tipoBanco].ToString(); 

    using (SharedDbConnectionScope scope = new SharedDbConnectionScope(conexao)) 
    { 
     //----------------------------------------------------------- 
     using (TransactionScope ts = new TransactionScope()) 
     { 
      Cargo c = new Cargo(); 
      c.LoadByKey(9999); 

      SubSonic.StoredProcedure sp = null; 
      sp = new SubSonic.StoredProcedure("sp_test"); 
      sp.Command.AddParameter("paramTabela", "zzz", DbType.AnsiStringFixedLength, null, null); 

      Convert.ToInt32(sp.ExecuteScalar()); 
     } 
    } 

web.configファイルは

<SubSonicService defaultProvider="mysql" enableTrace="false" templateDirectory=""> 
    <providers> 
     <clear/> 
    <add name="mysql" type="SubSonic.MySqlDataProvider, SubSonic" 
      regexDictionaryReplace="Empresaendereco,EmpresaEndereco;Empresacontato,EmpresaContato;Franqueadoendereco,FranqueadoEndereco;Franqueadocontato,FranqueadoContato;Funcionarioacesso,FuncionarioAcesso;Funcionarioendereco,FuncionarioEndereco;Funcionariocontato,FuncionarioContato;Clienteendereco,ClienteEndereco;Clientecontato,ClienteContato;Clientehistorico,ClienteHistorico;Agendastatus,AgendaStatus;Historicostatus,HistoricoStatus" 
      fixDatabaseObjectCasing="true" connectionStringName="mysql" 
      generateRelatedTablesAsProperties="true" 
      fixPluralClassNames="false" 
      generatedNamespace="ModeloDados" 
      regexIgnoreCase="true" 
      removeUnderscores="false" 
      setPropertyDefaultsFromDatabase="true" 
      generateNullableProperties="true" 
      useExtendedProperties="true" 
      useUtc="true" /> 

</providers> 
</SubSonicService> 
+0

[サブソニックとトランザクションを使用する](http://stackoverflow.com/questions/910863/using-transactions-with-subsonic) – Liam

答えて

3

私はあなたのTransactionScope()とSharedDbConnectionScope()はラウンド間違った方法だと思います。あなたはSubSonic Webサイトのドキュメントに記載されている順序でそれらを持っていますが、別の方法であるべきであることを意味する古いSubSonicフォーラムに関する議論がありました。

確かに私は逆にそれらを使用する(私はここに別の答えに私のコードの抜粋を掲載している)が、私は私だけMSSQL ATMを使う言わなければならない、とMySQLにコメントすることはできません。

+0

ありがとうkevinw、私は逆の順序で入れて... – Valmir