SUBSONIC MYSQL SharedDbConnectionScope TransactionScope

时间:2009-05-26 14:33:27

标签: subsonic

下一个代码在SQLSERVER中正常运行但是当我在 loadbykey 之后将web.config更改为使用mySQL运行时,连接已关闭。

是否有任何配置要在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>

1 个答案:

答案 0 :(得分:3)

我认为您的TransactionScope()和SharedDbConnectionScope()是错误的方式。您按照他们在SubSonic网站上的文档中列出的顺序拥有它们,但是在旧的SubSonic论坛上进行了讨论,暗示它们应该反过来。

当然我反过来使用它们(我刚刚在这里发布了我的代码的摘录到另一个答案),但我不得不说我只使用MSSQL ATM,并且不能评论MySQL。