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

查看:152
本文介绍了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天全站免登陆