Entity Framework on Azure function (Connectionstring problem)

Akarapol Prompiriyapong 6 Reputation points
2022-02-11T05:55:06.937+00:00

I want to insert or update on Azure function by Entity Framework.

I already created Azure function and ADO .NET from my SQL database. I inserted ConnectionString and ProviderName from ADO .NET to local.setting.json in Azure function.
173442-image.png

When I use model entities from ADO .NET Azure function the system will show the message below.
173348-image.png

Please suggest to me.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,299 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,397 questions
Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
558 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,431 Reputation points
    2022-02-11T10:34:22.507+00:00

    @Akarapol Prompiriyapong ,

    Thanks for reaching out to Q&A.

    The connection string should be configured under the "Connection Strings" section (underlined in below image) in the Configuration blade. After publishing, you need to make sure to set the appropriate application setting for "SqlConnectionString" with the production entity connection string. I would also suggest you to look into this article for using entity framework in Azure functions.

    173520-image.png

    I hope this helps!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


  2. wsiang 1 Reputation point
    2022-02-12T14:11:06.527+00:00

    Hi,

    Please try to put your connection string in local.settings.json as below:

    173746-image.png

    And then you can get the conn string to add it into the db context in your function's startup.cs

    public class Startup : FunctionsStartup  
        {  
            public override void Configure(IFunctionsHostBuilder builder)  
            {  
                FunctionsHostBuilderContext context = builder.GetContext();    
                string connString = context.Configuration.GetConnectionString("DataEntities");  
            }  
        }  
    

    Hope this could help you.