Fluent Nhibernate与MySQL的连接字符串
本文关键字:连接 字符串 MySQL Nhibernate Fluent | 更新日期: 2023-09-27 18:00:52
我已经阅读了《如何用MySQL配置Fluent NHibernate》一文,但我对MySQL相对陌生,我需要实际设置连接字符串本身。作为WAMP安装的一部分,我安装了MySQL,需要填写实际的连接字符串。有人能帮我扩展链接的答案,使其包含一个完整的连接字符串示例吗?
非常感谢。
编辑:我尝试了几种不同的方法,但一直收到以下错误消息:
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.
我通过nuget安装了FNH,我不明白为什么它会看到那个路径,因为d:驱动器是我的CD,而不是硬盘。非常困惑。
粘贴的错误看起来像Visual Studio试图本地化源以显示异常的来源。这不是真正的异常消息——你应该把它放在那里的某个地方,它可能是关于错误的配置。
如果您使用默认设置安装了WAMP,则它被配置为在3306端口上侦听,并且只有本地root
帐户而没有密码。所以你的连接字符串应该是这样的:
Server=localhost; Port=3306; Database=[database_name_here]; Uid=root; Pwd=;
(可能根本不需要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>
然后使用链接问题的解决方案:
MySqlConfiguration.Standard.ConnectionString(
c => c.FromConnectionStringWithKey("ConnectionString")
)
或者,您可以将连接字符串直接粘贴到Fluent的配置中,如下所示:
MySqlConfiguration.Standard
.ConnectionString.Is("Server=localhost; Port=3306;
Database=[database_name_here]; Uid=root; Pwd=;")
无论如何,这个默认的root/no-password配置只能用于本地开发和测试目的。