首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UseSqlServer函数.net 5 Azure配置

UseSqlServer函数.net 5 Azure配置
EN

Stack Overflow用户
提问于 2021-04-06 21:14:04
回答 2查看 126关注 0票数 1

我正在尝试用.net 5部署一个azure函数,"dotnet-isolated",但是我不能在上面运行sql server。这是我的配置启动

代码语言:javascript
复制
         static async Task Main(string[] args)
            {
    #if DEBUG
                Debugger.Launch();
    #endif
                var host = new HostBuilder()
                    .ConfigureAppConfiguration(c =>
                    {
                        c.AddCommandLine(args);
                    })
                    .ConfigureFunctionsWorkerDefaults((c, b) =>
                    {
                        b.UseFunctionExecutionMiddleware();
                    })
                    .ConfigureServices((context, services) =>
                                            {
                                                services.AddDbContext<ApplicationDbContext>(options =>
                                                    options.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection")));
                                            })
                    .Build();
                
                await host.RunAsync();
            }

看起来像

代码语言:javascript
复制
options.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection")))

无法识别Azure配置

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-04-06 22:31:51

问题出在ConfigureAppConfiguration上。必须是:

代码语言:javascript
复制
.ConfigureAppConfiguration(c =>
                {
                    c.AddEnvironmentVariables();
                    c.AddCommandLine(args);
                })

所以,最后的Main是:

代码语言:javascript
复制
 static async Task Main(string[] args)
        {
#if DEBUG
            Debugger.Launch();
#endif
            var host = new HostBuilder()
                .ConfigureAppConfiguration(c =>
                {
                    c.AddEnvironmentVariables();
                    c.AddCommandLine(args);
                })
                .ConfigureFunctionsWorkerDefaults((c, b) =>
                {
                    b.UseFunctionExecutionMiddleware();
                })
                .ConfigureServices((context, services) =>
                                        {
                                            services.AddDbContext<ApplicationDbContext>(options =>
                                                options.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection")));
                                        })
                .Build();
            
            await host.RunAsync();
        }
票数 1
EN

Stack Overflow用户

发布于 2021-04-06 21:21:12

似乎azure没有连接到你的构建,要么是因为你的配置不稳定,要么是因为你想让它如此快地处理过多的sql数据。我猜是第二种。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66969374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档