Fluent Nhibernate与MySQL的连接字符串

kir*_*rps 4 c# mysql nhibernate fluent-nhibernate

我已经回顾了如何使用MySQL配置Fluent NHibernate的帖子,但我对MySQL相对较新,我需要实际设置连接字符串本身.我已经安装了MySQL作为WAMP安装的一部分,需要填写实际的连接字符串.有人可以通过扩展链接的答案实际包含完整的连接字符串示例来帮助我吗?

赞赏.

编辑:我已经尝试了几个不同的东西,我不断收到以下错误消息:

Can't load file FluentConfiguration.cs under d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg.
Check the file permission and the existence of that file.
Run Code Online (Sandbox Code Playgroud)

我通过nuget安装了FNH,我不明白为什么它正在查看那条路径,因为d:驱动器是我的CD而不是硬盘.非常困惑.

NOt*_*Dev 5

您粘贴的错误看起来像Visual Studio尝试本地化源以显示异常的来源.这不是真正的异常消息 - 你应该把它放在那里,它可能是错误的配置.

如果您已使用默认设置安装WAMP,则将其配置为侦听3306端口并且仅具有root没有密码的本地帐户.所以你的连接字符串看起来应该是这样的:

Server=localhost; Port=3306; Database=[database_name_here]; Uid=root; Pwd=;
Run Code Online (Sandbox Code Playgroud)

(Pwd=部分可能根本不需要).

所以,你需要把它贴在你App.config/ Web.config<connectionStrings>部分:

<connectionStrings>
    <add name="ConnectionString" 
         connectionString="Server=localhost; Port=3306; 
              Database=[database_name_here]; Uid=root; Pwd=;" 
         providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

然后使用链接问题的解决方案:

MySqlConfiguration.Standard.ConnectionString(
    c => c.FromConnectionStringWithKey("ConnectionString")
)
Run Code Online (Sandbox Code Playgroud)

或者,您可以将连接字符串直接粘贴到Fluent的配置中,如下所示:

MySqlConfiguration.Standard
    .ConnectionString.Is("Server=localhost; Port=3306;
        Database=[database_name_here]; Uid=root; Pwd=;")
Run Code Online (Sandbox Code Playgroud)

无论如何,这个默认的root/no password配置只能用于本地开发和测试目的.