Fluent Nhibernate 与 MySQL 的连接字符串

发布于 2024-11-17 23:53:27 字数 588 浏览 1 评论 0原文

我已经阅读了这篇文章How to configure Fluent NHibernate with MySQL,但我对 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.

我通过 nuget 安装了 FNH,但我不明白为什么它会查看该路径,因为 d: 驱动器是我的CD而不是硬盘。很困惑。

I've reviewed the post How to configure Fluent NHibernate with MySQL, but I'm relatively new to MySQL and I need to actually set up with connection string itself. I've installed MySQL as part of a WAMP install and need to fill in the actual connection string. Can someone help me by extending the linked answer to actually contain a full connection string example?

Appreciated.

Edit: I've tried several different things and I keep getting the following error message:

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.

I installed FNH via nuget, and I don't understand why it's looking at that path, as the d: drive is my CD and not a harddisk. Very confused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴者 2024-11-24 23:53:27

您粘贴的错误看起来像是 Visual Studio 试图本地化源以向您显示异常的来源。这不是真正的异常消息 - 你应该把它放在某个地方,它可能与错误的配置有关。

如果您使用默认设置安装了 WAMP,它会配置为侦听 3306 端口,并且只有本地 root 帐户而无需密码。所以你的连接字符串应该看起来像这样:(

Server=localhost; Port=3306; Database=[database_name_here]; Uid=root; Pwd=;

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

因此,您需要将其粘贴到 App.config/Web.config 部分:

<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/无密码配置只能用于本地开发和测试目的。

The error you've pasted looks like Visual Studio trying to localise the sources to show you where the exception comes from. This is not the real exception message - you should have it somewhere there and it's probably something about wrong configuration.

If you've installed WAMP with default settings, it is configured to listen on 3306 port and have only local root account without password. So your connection string should look somehow like that:

Server=localhost; Port=3306; Database=[database_name_here]; Uid=root; Pwd=;

(Pwd= part may be not needed at all).

So you need to paste it in your App.config/Web.config's <connectionStrings> section:

<connectionStrings>
    <add name="ConnectionString" 
         connectionString="Server=localhost; Port=3306; 
              Database=[database_name_here]; Uid=root; Pwd=;" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

and then use the solution from linked question:

MySqlConfiguration.Standard.ConnectionString(
    c => c.FromConnectionStringWithKey("ConnectionString")
)

Alternatively, you can paste the connection string directly in your Fluent's configuration, like this:

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

Anyway, this default root/no password configuration can be used only for local development and testing purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文