Azure Functions 数据库连接字符串 [英] Azure Functions Database Connection String

查看:31
本文介绍了Azure Functions 数据库连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Azure 函数中添加或访问 app.config 文件以添加数据库连接字符串?

How do I add or access an app.config file in Azure functions to add a database connection string?

如果您不应该添加 app.config 并且有更好的方法来访问外部数据库以执行该功能,请告诉我最佳实践.谢谢!

If you're not supposed to add an app.config and there is a better way to access an external database to execute the function please let me know best practices. Thanks!

推荐答案

Jan_V 几乎 解决了这个问题,这让我在 local.settings.json 中尝试了这个

Jan_V almost nailed it, which led me to experiment with this in the local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true;",
    "AzureWebJobsDashboard": ""
  },
  "ConnectionStrings": {
    "MyConnectionString": "[YourConnectionStringHere]"
  }
}

这允许您使用我们都习惯的ConfigurationManager.ConnectionStrings[].

This allows you to use the ConfigurationManager.ConnectionStrings[] we are all used to.

var sqlConnection = ConfigurationManager
                   .ConnectionStrings["MyConnectionString"].ConnectionString;

这篇关于Azure Functions 数据库连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆