不能使用具有亚音速数据访问的DLL

时间:2010-07-08 09:15:10

标签: c# mysql subsonic data-access-layer

我使用亚音速3.0生成了我的dataaccess dll。我有一个新的项目参考这个DLL,我尝试将数据插入我的mysql数据库。 我收到以下配置错误。但是当我查看我的App.config时,我有一个连接字符串来定义我的数据库连接。

  <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>

    <add name="dbTorontoTrader"
       connectionString="server=localhost;database=dbtorontotrader;user id=root; password=password"
       providerName="MySql.Data.MySqlClient"/>
    <!-- For MySQL -->
  </connectionStrings>
  <system.data>
    <DbProviderFactories>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.1.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
</configuration>

System.Configuration.ConfigurationErrorsException was unhandled
  Message="Failed to find or load the registered .Net Framework Data Provider."
  Source="System.Data"
  BareMessage="Failed to find or load the registered .Net Framework Data Provider."
  Line=0
  StackTrace:
       at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
       at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
       at SubSonic.DataProviders.DbDataProvider..ctor(String connectionString, String providerName)
       at SubSonic.DataProviders.ProviderFactory.LoadProvider(String connectionString, String providerName)
       at SubSonic.DataProviders.ProviderFactory.GetProvider(String connectionStringName)
       at TorontoTrader.Data.Ver2.dbTorontoTraderDB..ctor() in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderDataVer2\Context.cs:line 37
       at TorontoTrader.Data.Ver2.scans_log.GetRepo(String connectionString, String providerName) in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderDataVer2\ActiveRecord.cs:line 10338
       at TorontoTrader.Data.Ver2.scans_log.GetRepo() in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderDataVer2\ActiveRecord.cs:line 10354
       at TorontoTrader.Data.Ver2.scans_log.SingleOrDefault(Expression`1 expression) in E:\TradingTools\CODE\TorontoTraderDataVer2\TorontoTraderDataVer2\ActiveRecord.cs:line 10359
       at ConsoleApplication1.Program.Main(String[] args) in E:\TradingTools\CODE\TorontoTraderDataVer2\ConsoleApplication1\Program.cs:line 13
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

2 个答案:

答案 0 :(得分:1)

您的应用配置应如下所示:

<configuration>
    <connectionStrings>
        <add name="dbTorontoTrader" connectionString="server=localhost;database=dbtorontotrader;user id=root; password=password" providerName="MySql.Data.MySqlClient"/>
     </connectionStrings>
</configuration>

记下缺少的元素

答案 1 :(得分:1)

您需要添加connectionstrings元素。

您的app.config应如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="dbTorontoTrader"
         connectionString="server=localhost;database=dbtorontotrader;user id=root; password=password"
         providerName="MySql.Data.MySqlClient"/>
  </connectionStrings>
</configuration>