0

I am using managed identity to login to Azure database. Most connections are done through Nhibernate. When i call the following

 FluentConfiguration fluent;
            fluent = Fluently.Configure()
                .Database(
                    MsSqlConfiguration.MsSql2005
                        .ConnectionString(c => c
                            .Is(connstring))
                )

The connString is

string ConnectionString =  @"Server=demo- 
server.database.windows.net,1433;Authentication=Active Directory Default; 
Encrypt=True;Database=DEMO";

It gives an error:

FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. 

Invalid Value for key 'authentication'

Any ideas on how to fix this ?

Jennifer
  • 31
  • 6
  • might be this problem https://stackoverflow.com/a/69109716/671619 – Firo Feb 02 '23 at 16:21
  • tried these suggestions ,looks like they are for Entity Framework, im using Nhibernate. They didnt seem to work. Is there a newer version of Nhibernate that supports Managed Identity ? – Jennifer Feb 03 '23 at 01:34
  • it is about the driver used. It is different to configure in NHibernate but should solve it. – Firo Feb 06 '23 at 07:03

1 Answers1

0

You need to use MicrosoftDataSqlClientDriver driver (available since NHibernate v5.3+). And make sure you are referencing Microsoft.Data.SqlClient v3+ version.

Your Fluent database configuration should look something like:

Fluently.Configure()
    .Database(
        MsSqlConfiguration.MsSql2012
            .Driver<MicrosoftDataSqlClientDriver>()
            .ConnectionString(connectionString)
    )
Roman Artiukhin
  • 2,200
  • 1
  • 9
  • 19
  • This works if i run from VS under my identity which is SQL Server admin, but the app service is called TestAppMI and after creating an identity there is a System assigned managed identity created as TestAppMI with an Object Principal ID. I have given this id access to the db but it gives error System.BadImageFormatException · Could not load file or assembly 'Microsoft.Identity.Client, Version=4.39.0.0, Although I have selected the latest versions in all . Any ideas on this ? – Jennifer Feb 07 '23 at 23:55
  • Do you have explicit `Microsoft.Identity.Client` project reference in your project? Try removing it or using 4.39.0 version. – Roman Artiukhin Feb 08 '23 at 06:30
  • Also read this: https://github.com/dotnet/SqlClient/issues/763 – Roman Artiukhin Feb 08 '23 at 06:32
  • If i remove Microsoft.Identity.Client from the project I get then get an error "Invalid value for key 'authentication" – Jennifer Feb 08 '23 at 21:07