Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#EF SQL应用程序在手动运行时可以移动文件,但在由任务调度器运行时不能移动文件_C#_Sql_Windows_Entity Framework - Fatal编程技术网

C#EF SQL应用程序在手动运行时可以移动文件,但在由任务调度器运行时不能移动文件

C#EF SQL应用程序在手动运行时可以移动文件,但在由任务调度器运行时不能移动文件,c#,sql,windows,entity-framework,C#,Sql,Windows,Entity Framework,我的错误日志如下所示: 2020-11-09 12:33:31.4463||ERROR|FolderClean.Worker.Workers.FolderCleanWorker|Value cannot be null. (Parameter 'connectionString') |url: |action: 2020-11-09 12:33:31.4463||ERROR|FolderClean.Worker.Workers.FolderCleanWorker|Error on File:

我的错误日志如下所示:

2020-11-09 12:33:31.4463||ERROR|FolderClean.Worker.Workers.FolderCleanWorker|Value cannot be null. (Parameter 'connectionString') |url: |action: 
2020-11-09 12:33:31.4463||ERROR|FolderClean.Worker.Workers.FolderCleanWorker|Error on File: \\alaris-prod\Batches\BatchTestingComponent\Renal\RenalBatch000002204 XAX\info |url: |action: 
2020-11-09 12:33:31.4463||ERROR|FolderClean.Worker.Workers.FolderCleanWorker|Value cannot be null. (Parameter 'connectionString') |url: |action: 
2020-11-09 12:33:31.4775||ERROR|FolderClean.Worker.Workers.FolderCleanWorker|Value cannot be null. (Parameter 'from')
我的连接字符串是:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=sb-sql;Database=AlarisSBStats;Trusted_Connection=True;"
}
其中:

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseWindowsService()
                .ConfigureServices((hostContext, services) =>
                {
                    IConfiguration configuration = hostContext.Configuration;
                    services.Configure<EmailOption>(configuration.GetSection("Smtp"));
                    services.AddScoped(p =>
                    {
                        var connectionString = configuration["ConnectionStrings:DefaultConnection"];
                        return new ApplicationDbContext(connectionString);
                    });
公共静态IHostBuilder CreateHostBuilder(字符串[]args)=>
Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureServices((主机上下文,服务)=>
{
IConfiguration configuration=hostContext.configuration;
services.Configure(configuration.GetSection(“Smtp”));
services.AddScoped(p=>
{
var connectionString=configuration[“ConnectionStrings:DefaultConnection”];
返回新的ApplicationDbContext(connectionString);
});
该应用程序在手动运行时按预期工作,但作为计划任务,我收到上面的日志错误。它读取的值为0。不确定为什么它不能手动工作

 var connectionString = "Server=sb-sql; Database=AlarisSBStats;Trusted_Connection=True";
硬编码,它工作了


将其硬编码并成功!

您是在设置计划任务时设置特定凭据,还是作为系统运行?通过启用所有权限的管理员帐户运行本地管理员或域?看起来您正在访问网络共享。您确定执行此代码的帐户可以查看网络吗共享?是的,因为它在手动模式下也能工作,而在以前的版本中,当源文件夹和目标文件夹是网络共享驱动器时,它也能工作。现在的问题是当我连接到SQL数据库时。您是在设置计划任务时设置特定凭据,还是作为系统运行?通过管理员运行启用所有权限的IStrotor帐户本地管理员或域?看起来您正在访问网络共享。您确定正在执行此代码的帐户可以看到网络共享吗?是的,因为它在手动模式下工作,在以前的版本中,当源文件夹和目标文件夹为网络共享dri时,它也工作现在的问题是当我连接到SQL数据库时。