错误:尝试调用函数app时,初始化字符串的格式不符合从索引0开始的规范. [英] Error : Format of the initialization string does not conform to specification starting at index 0. when trying to invoke the function app

查看:71
本文介绍了错误:尝试调用函数app时,初始化字符串的格式不符合从索引0开始的规范.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试已部署的Azure功能,并收到以下错误.我的函数在本地连接到Azure数据库上运行,但是在部署和运行时失败.我已经配置了应用程序设置,以读取连接字符串的秘密URL.

I am testing my deployed Azure function and getting the following error. My function runs locally connecting to Azure database but fails when its deployed and run. I have configured the application settings to read the secret url to the connection string.

这是我的连接字符串的样子

This is how my connectionstring looks like

Server=tcp:ranjitazuredb.database.windows.net,1433;Initial Catalog=Srl;Persist Security Info=False;User ID=usr;Password=pwd;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

应用程序设置-秘密秘诀

Application setting - Url to the secret

https://srlcustomermanagervault.vault.azure.net/secrets/ConnectionString

功能

public  class GetCustomersOrders
    {
        private readonly ICustomerOrdersRepository _repo;
        private readonly IMapper _mapper;
        private readonly TelemetryClient _telemetryClient;


        public GetCustomersOrders(ICustomerOrdersRepository repo, IMapper mapper, TelemetryConfiguration configuration)
        {
            _repo = repo;
            _mapper = mapper;
            _telemetryClient = new TelemetryClient(configuration);
        }

        [FunctionName("GetCustomersOrders")]
        public async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "customer-orders")] HttpRequest req,
            ILogger log)
        {
            this._telemetryClient.TrackTrace("C# HTTP trigger function processed a request.");
            var customersOrders = _repo.GetCustomerOrders();
            return new OkObjectResult(_mapper.Map<List<CustomerOrdersViewModel>>(customersOrders));
        }
    }

这是我分配政策的方式

功能启动

[assembly: FunctionsStartup(typeof(Startup))]
namespace SRL.CustomerOrder
{
    internal class Startup : FunctionsStartup
    {
      
        public override void Configure(IFunctionsHostBuilder builder)
        {
           
                var connectionString = Environment.GetEnvironmentVariable("ConnectionString");

                builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
                builder.Services.AddScoped<ISrlContext, CustomerManagerContext>();
                builder.Services.AddAutoMapper(typeof(Startup));

                builder.Services.AddDbContext<CustomerManagerContext>(options =>
                   options.UseSqlServer(connectionString));

                builder.Services.AddTransient<ICustomerDetailsRepository, CustomerDetailsRepository>();
                builder.Services.AddTransient<ICustomerOrdersRepository, CustomerOrdersRepository>();
                builder.Services.AddTransient<IOrderDetailsRepository, OrderDetailsRepository>();

        }

    }
}

推荐答案

假设在应用程序设置中直接使用连接字符串时,该连接字符串有效,我将检查此链接 https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references

Presuming the connection string worked when you used it directly in the app settings I would check out this link https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references

因此在您的示例中,您将使用

So in your example you would use

@ Microsoft.KeyVault(SecretUri = https://srlcustomermanagervault.vault.azure.net/secrets/ConnectionString)

@Microsoft.KeyVault(SecretUri=https://srlcustomermanagervault.vault.azure.net/secrets/ConnectionString )

文档说您需要版本ID,但您不需要版本ID(这是一个有效的错误).Azure正在开发一个发行版,因此它可以在没有版本的情况下正常运行,该版本可能现在就已经发布了,即使不是很快也可以发布.我已经与几个人进行过交谈,并使其在没有版本的情况下为客户服务.

The documentation says you need the version id but you do not, (it is a bug that it works). Azure is working on a release so that it works without a version which should probably be out in preview by now and if not shortly. I have talked with several people and have it working for a client without the version.

这篇关于错误:尝试调用函数app时,初始化字符串的格式不符合从索引0开始的规范.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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