首页 \ 问答 \ Windows任务计划程序在运行提交给svn的批处理文件时挂起(Windows Task Scheduler hanging when running a batch file that commits to svn)

Windows任务计划程序在运行提交给svn的批处理文件时挂起(Windows Task Scheduler hanging when running a batch file that commits to svn)

我在批处理文件中使用svn命令行客户端将单个文件提交到源代码管理。

"%TortoiseSVNPath%\svn.exe" commit %LocalPath%\backup.sql -m "Committing Backup"

这运行正常,当我运行它。 我想将它设置为每天晚上使用Windows任务计划程序运行。 但是,当我这样做时,它就陷入了这条线。 我发现问题发生是因为创建任务的用户没有登录到系统中。 有没有办法连接到svn,即使他们没有登录?

任何帮助将不胜感激。


I have the following in a batch file that uses the svn command line client to commit a single file to source control.

"%TortoiseSVNPath%\svn.exe" commit %LocalPath%\backup.sql -m "Committing Backup"

This works fine when I run it. I'd like to set it up to run every night using Windows Task Scheduler. However, when I do so, it gets stuck at that line. I've discovered that problem occurs because the user the task was created under was not logged into the system. Is there a way to connect to svn, even if they're not logged in?

Any help would be greatly appreciated.


原文:https://stackoverflow.com/questions/16488412
更新时间:2024-02-02 14:02

最满意答案

我开始写评论,但这太长了。

LINQ-to-SQL中的参数化查询应该对您有用。 像这样的东西:

StringBuilder sbSQL = new StringBuilder(
       "INSERT INTO [table] ([fk_id], [Description], [Title] ) VALUES");

int paramNum = 0;
List<object> paramValues = new List<object>();

foreach(var item in items) 
{
    sbSQL.AppendFormat("({{{0}}},{{{1}}},{{{2}}}),", 
        paramNum, 
        paramNum + 1, 
        paramNum + 2);

    paramValues.Add(item.fk_id);
    paramValues.Add(item.description);
    paramValues.Add(item.title);

    paramNum += 3;
}

myDataContext.ExecuteCommand(
    sbSQL.Remove(sbSQL.Length - 1, 1).ToString(), 
    paramValues.ToArray());

ExecuteCommand函数只接受您的SQL命令,其中包含与标准.NET字符串格式化函数兼容的标记( {0} ),然后将您传递的值转换为参数,并使用其生成的参数名称代替标记。 您可以自己编写命令并根据需要排列参数; 它不会检查或解析命令。


I started writing a comment, but this was too long.

The parameterized queries in LINQ-to-SQL should do just fine for you. Something like this:

StringBuilder sbSQL = new StringBuilder(
       "INSERT INTO [table] ([fk_id], [Description], [Title] ) VALUES");

int paramNum = 0;
List<object> paramValues = new List<object>();

foreach(var item in items) 
{
    sbSQL.AppendFormat("({{{0}}},{{{1}}},{{{2}}}),", 
        paramNum, 
        paramNum + 1, 
        paramNum + 2);

    paramValues.Add(item.fk_id);
    paramValues.Add(item.description);
    paramValues.Add(item.title);

    paramNum += 3;
}

myDataContext.ExecuteCommand(
    sbSQL.Remove(sbSQL.Length - 1, 1).ToString(), 
    paramValues.ToArray());

The ExecuteCommand function just takes your SQL command, complete with tokens ({0}) compatible with standard .NET string formatting functions, then turns the values you pass into parameters and uses its generated parameter names in place of the tokens. It's up to you to write the command and arrange the parameters however you like; it's not going to inspect or parse the command.

相关问答

更多