ErikEJ / EntityFramework6PowerTools

This is the codebase for Entity Framework 6 Power Tools Community Edition, and modern EF 6 providers for SQL Server and SQL Server Compact
Other
183 stars 27 forks source link

Invalid value for key 'authentication' #130

Closed VigneashSelvaraj closed 11 months ago

VigneashSelvaraj commented 11 months ago

Hi - when I use Authentication key in my SQL connection string, I see above error. Can EF not process non sql auth ?

ErikEJ commented 11 months ago

It can, provided you use the correct underlying driver. When and where do you se this? In which VS version using which DDEX provider?

VigneashSelvaraj commented 11 months ago

Mine is a web app (.NET Framework 4.6) hosted on Azure app service which connects Azure SQL server via SQL authentication (username/password) using Entity Framework inheriting from DbContext class from System.Data.Entity namespace.

I’m planning to use Active Directory Service Principal authentication mode. Due to this I modified my connection string like “Data Source= servername.database.windows.net; Encrypt=True; Initial Catalog= dbname; Authentication=Active Directory Service Principal; User Id=servicePrincipalID; Password=servicePrincipalPassword;”

Modified string throws System.ArgumentException: 'Invalid value for key 'authentication'.' error when trying to open the connection. Many online articles/resources have clear integration for .Net core apps using Microsoft.EntityFrameworkCore assembly, however nothing much for .Net Framework app.

ErikEJ commented 11 months ago

Ah! You should use: https://github.com/ErikEJ/EntityFramework6PowerTools/blob/community/src/ErikEJ.EntityFramework.SqlServer/readme.md

VigneashSelvaraj commented 11 months ago

from the above readme file, does the DbContext class comes from System.Data.Entity namespace ?

ErikEJ commented 11 months ago

Yes

VigneashSelvaraj commented 11 months ago

Below is my app db context class using System; using System.Data.Entity; using System.Data.Entity.SqlServer;

namespace SampleApp.Databases { [DbConfigurationType(typeof(MicrosoftSqlDbConfiguration))] public class SampleAppContext : DbContext, IDisposable, IContentValidationContext { public SampleAppContext(string connectionString) : base(connectionString) {

    }

Error I see: System.ArgumentException HResult=0x80070057 Message=Invalid value for key 'authentication'. Source= StackTrace:

VigneashSelvaraj commented 11 months ago

and the connection string is “Data Source= servername.database.windows.net; Encrypt=True; Initial Catalog= dbname; Authentication=Active Directory Service Principal; User Id=servicePrincipalID; Password=servicePrincipalPassword;”

ErikEJ commented 11 months ago

Please share a full repro if you want free support. Do you get this error locally or on your app service?

VigneashSelvaraj commented 11 months ago

This happens in my local.

ErikEJ commented 11 months ago

Maybe duplicate of https://github.com/ErikEJ/EntityFramework6PowerTools/issues/129 - otherwise share a full repro project.

VigneashSelvaraj commented 11 months ago

Could you please review https://github.com/VigneashSelvaraj/SqlServerAuthFramework/tree/master

ErikEJ commented 11 months ago

@VigneashSelvaraj Thanks, please share some repro steps.

Why are you not using .NET ??

ErikEJ commented 11 months ago

Use this config! That is why it is important to share all details!

  <connectionStrings>
      <add 
              name="SqlConnectionString" 
             connectionString="Data Source=servrename.database.windows.net;Encrypt=True;Initial Catalog=dbname;Authentication=Active Directory Service Principal;User Id=userid;Password=password;" 
             providerName="Microsoft.Data.SqlClient" />
  </connectionStrings>
VigneashSelvaraj commented 11 months ago

thanks, it worked

ErikEJ commented 11 months ago

You are welcome

If you like my free tools, I would be very grateful for a rating or review on Visual Studio Marketplace or even a one-time or monthly sponsorship

VigneashSelvaraj commented 11 months ago

Hi @ErikEJ

In my web app, I do have a Business logic project holding Dbcontext. Can I just install ErikEJ.EntityFramework.SqlServer package in Business logic project alone ? (or) do I have to install the same package in that web project calling BL project ?

ErikEJ commented 11 months ago

@VigneashSelvaraj What have you tried? Also, this issue is closed.