使用MySQL连接BLToolkit [英] BLToolkit using a MySQL connection

查看:641
本文介绍了使用MySQL连接BLToolkit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立使用BLToolkit一个MySQL服务器的连接,并已通过的NuGet安装My​​Sql.Data(6.5.4),BLToolkit(4.1.12)和BLToolkit.MySql(4.1.12)。我可以在一行到MSSQL服务器的连接,但遇到了麻烦与MySQL和结束了与下面的配置文件...

I am making an attempt to establish a connection to a MySQL server using BLToolkit, and have installed MySql.Data (6.5.4), BLToolkit (4.1.12) and BLToolkit.MySql (4.1.12) via NuGet. I can make a connection to a MSSQL server in a single line, but have had trouble with MySQL and ended up with the following configuration file ...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <BLToolkit>
        <dataProviders>
            <add type="BLToolkit.Data.DataProvider.MySqlDataProvider" />
        </dataProviders>
    </BLToolkit>
    <configSections>
        <section name="BLToolkit" type="BLToolkit.Configuration.BLToolkitSection, BLToolkit.4" />
    </configSections>
    <connectionStrings>
        <add name="Test"
             connectionString="Data Source=localhost;Port=3306;Database=bltest;User ID=root;Password=root;"
             providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
</configuration>

我已经扩展了DbManager类来实现一个参照表,并通过连接字符串到基类的名称。这是我是如何实现这种行为,应告诉BLToolkit从配置文件加载的connectionString ...

I have extended the DbManager class to implement a reference to the tables, and passed the name of the connection string into the base class. This is how I implemented this behaviour, which should be telling BLToolkit to load the connectionString from the configuration file ...

class BlDb : DbManager {
    public BlDb()
        : base("Test") {
        return;
    }
    public Table<Car> Car { get { return GetTable<Car>(); } }
    public Table<Make> Make { get { return GetTable<Make>(); } }
}

这是例外,然而,被抛出。唯一的例外是的类型初始BLToolkit.Data.DbManager'引发了异常。与内例外是配置系统初始化失败。我该如何操作?请注意,类似的问题也对SO,存在获取BLToolkit与MySQL ,这可能是为你提供有益的参考,但不做出任何任何意义了我。是否同时安装的NuGet包还不够吗?

An exception, however, is thrown. The exception is "The type initializer for 'BLToolkit.Data.DbManager' threw an exception." with the inner exception being "Configuration system failed to initialize". How should I proceed? Please note that a similar question does exist on SO, Getting BLToolkit to work with MySQL, which might be a helpful reference for you but doesn't make any sense whatsoever to me. Is installing both NuGet packages not enough?

推荐答案

Firts您需要将引用添加到 BLToolkit.Data.DataProvider.MySql.4.dll 到项目中。然后修改扩展DbManager类看起来以下

Firts you need to add the reference to the BLToolkit.Data.DataProvider.MySql.4.dll to your project. Then modify your extended DbManager class to look as the following

class BlDb : DbManager
{
    public BlDb()
        : base( new BLToolkit.Data.DataProvider.MySqlDataProvider(), "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword" )
    {           
    }
    public Table<Car> Car { get { return GetTable<Car>(); } }
    public Table<Make> Make { get { return GetTable<Make>(); } }
}

您可以取代硬codeD连接字符串,就从 ConfigurationManager.ConnectionStrings [测试]您app.config文件返回。ConnectionString的

you can replace the hard-coded connection string and return it from your app.config file like ConfigurationManager.ConnectionStrings["Test"].ConnectionString

这篇关于使用MySQL连接BLToolkit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆