kirps kirps - 7 months ago 65
SQL Question

Connection string for Fluent Nhibernate with MySQL

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.

Answer

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.