【问题标题】:SUBSONIC MYSQL SharedDbConnectionScope TransactionScopeSUBSONIC MYSQL SharedDbConnectionScope TransactionScope
【发布时间】:2023-03-31 21:46:01
【问题描述】:

下一个代码在 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>

【问题讨论】:

标签: subsonic


【解决方案1】:

我认为您的 TransactionScope() 和 SharedDbConnectionScope() 是错误的方式。您可以按照它们在 SubSonic 网站上的文档中列出的顺序来获取它们,但是在旧的 SubSonic 论坛上有一个讨论暗示它们应该是相反的。

当然,我将它们颠倒使用(我刚刚将我的代码摘录发布到此处的另一个答案),但我不得不说我只使用 MSSQL ATM,不能对 MySQL 发表评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多