1

I am getting above error in Azure function. When I am trying to establish connection with my database using Entity Framework from Azure function.

I read some posts which suggests to change Connection Type to "Custom" from "SQL Server" but after doing that I am getting the application's configuration file does not contain the required providerName attribute. error.

enter image description here

Now I tried many things to resolve this but no success yet.

Here is my connection string -

metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string='data source=*******;initial catalog=****;persist security info=True;user id=****;password=*******;MultipleActiveResultSets=True;App=EntityFramework

Please help.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
SharadG
  • 165
  • 3
  • 10

3 Answers3

1

You could check the official EF connection string on your side.
I suppose your issue is related with the conflict between Azure portal connection string and web.config connection string. And we can not define providerName attribute in connection string in portal.

You could learn more about the conflict connection string from this article.

The portal doesn't have the capabilities to accept the providerName attribute. As such, you need to keep the connection string in your web.config, which specifies the name and the providerName but just put in a dummy value for the connection string. Now put that connection string value in the portal connection string. When it runs, it will pick up the providerName from the web.config, but then overwrite your dummy connection string that is in the web.config with the connection string value you put in Azure portal Application Settings [Connection Strings].

There is one solution in this article.

Try publishing with a local or dummy connection string in place, and overwriting it as you have in the Azure Application Settings.

Janley Zhang
  • 1,567
  • 7
  • 11
1

You probably solved your issue already but I ran into the same problem today. I solved it as following.

  • Created a separate project for the EF model.
  • Add the following code to extend the entities class

    [DbConfigurationType(typeof(DBContextConfig))]
    partial class <Entities Class Name>
    {
    
        public Entities(string connectionString)
          : base(connectionString)
        {
        }
    }
    
    public class DBContextConfig : DbConfiguration
    {
        public DBContextConfig()
        {
            SetProviderServices("System.Data.EntityClient", SqlProviderServices.Instance);
            SetDefaultConnectionFactory(new SqlConnectionFactory());
        }
    }
    
  • Reference project in Azure Function project.
  • Add connection string to Application Settings in Azure Portal and set connection type to Custom.
Guido Neele
  • 778
  • 1
  • 7
  • 20
0

I resolved this by overriding auto generated Entities class with parameterised constructor(connection string as parameter).

SharadG
  • 165
  • 3
  • 10