Error : Format of the initialization string does not conform to specification starting at index 0. when trying to invoke the function app

血红的双手。 提交于 2021-02-11 13:38:47

问题


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

Function

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));
        }
    }

This is how I have assigned the policy

Function start up

[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>();

        }

    }
}

回答1:


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 )

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.



来源:https://stackoverflow.com/questions/62898592/error-format-of-the-initialization-string-does-not-conform-to-specification-st

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!