none
The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers. RRS feed

  • Question

  • Up until now, all my projects are 4.6.1 (.NET Framework, and not .NET Core).

    I have several data access layers, in this case I'm using EF 6 to connect to a SQL Azure database.  This is the connectionstring:

    metadata=res://Email/DAL.DataAccess.MasterEmail.MasterEmail.csdl|res://Email/DAL.DataAccess.MasterEmail.MasterEmail.ssdl|res://Email/DAL.DataAccess.MasterEmail.MasterEmail.msl;provider=System.Data.SqlClient;provider connection string='Server=tcp:sqlqa.database.windows.net,1433;Initial Catalog=<MyDatabaseName>;Persist Security Info=False;User ID=<myUserIdPlainText>;Password=<MyPasswordPlainText>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;'

    I'm new to Azure functions, but I added one, which is Azure Functions v1 (.NET Core), not v2.

    Locally, the Azure function reads this connection string from local.settings.json, and runs to completion.

    I set up a Build and Release for this Azure Function on Azure DevOps, and followed instructions I found online where it instructed me to copy my config settings over to Application Settings.  In this case, the connection string is an app setting, rather than a connection string.  It's just that way. I can see that the Azure Function reads this connection string, but when it goes to read from the database:

     return unitOfWork.MasterEmailContext.SenderServices
                    .Include("SenderService_Company")
                    .Where(i => i.is_active && (i.avail_to_all || i.SenderService_Company.Any(j => j.company_id == companyId)))
                    .OrderBy(i => i.priority)
                    .ToList()
                    .Select(i => FromEntity(i))
                    .ToList();

    It generates this exception:

    The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded.

    The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers.

    I believe I understand the root cause: It seems Azure functions don't have access to all the various providers, and so expect you to somehow load the provider.

    I've tried modifying my DbContext Configuration with SetProviderServices which didn't make any difference.

    I've tried upgrading my Azure Function to v2, so I could DbProviderFactories.RegisterFactory, which caused a whole different exception.

    Is there a straightforward way to get my Azure function to work without changing the underlying data access layer?

    Thanks!


    Monday, September 23, 2019 1:17 AM

All replies

  • Hi John 94127,

    Please see: Azure Functions runtime versions overview

    You need to be using .NET Core 2.2 with Azure Functions 2.x and .NET Framework 4.7 with Azure Functions 1.x.

    Please let me know if you have additional questions.

    Regards,

    Mike

    Tuesday, September 24, 2019 3:17 AM
    Moderator
  • Hello Mike,

    I'm running azure function 1x and my library is in .net framework 4.7 . However I still get the "The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers" exception.

    thanks,

    Sunil

    Wednesday, November 20, 2019 9:55 AM
  • Hi Sunil,

    Can you take a look at the following Stack Overflow thread: Entity Framework ADO.NET Sql.Data.Client provider not found

    There seems to be multiple possibilities to a root cause. Please take a look at the answers presented and see one of the listed solutions resolves your specific issue.

    Please let me know if you resolve your issue, and post that here so as to assist others experiencing the same issue.

    ~Mike

    Wednesday, November 20, 2019 11:37 PM
    Moderator