无法让 Windows 任务计划程序运行计划的控制台应用程序
我有一个控制台应用程序,它使用两个批处理文件来解压缩 zip 文件,将解压缩的 xls 将其转换为 CSV,并将数据 BCP 转换为 SQL 表。 我想安排这个控制台应用程序每天运行一次。 我设置了 Windows 任务计划程序来运行所述应用程序。 我尝试“测试运行”该任务,但没有收到错误。 当捕获异常时,我让应用程序写入 txt 文件,并且出现“您尝试使用的 xls 文件正在被另一个进程使用”的错误。
注意:我知道有更有效的方法可以完成将 xls 导入到 SQL,但它适用于那些因为太便宜而无法购买完整版 SQL SERVER 的客户。
I have a console app that uses two batch files to decompress a zip file, take the xls which was decompressed convert it to CSV and BCP the data into a SQL table. I'd like to schedule this console app to run once a day. I set up windows task scheduler to run said app. I try to "test run" the task and don't get an error. I have the app writing to a txt file when exceptions are caught and i get an error along the lines of "the xls file you are trying to use is being used by another process".
NOTE: I know there are more efficiant ways of accomplishing the importation of xls to SQL, but it is for a client who is too cheap to buy a FULL version of SQL SERVER.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
某些东西尚未释放它对 XML 文件的保留。 您需要找出哪些其他程序正在使用该资源,并确保其连接已关闭。 可能是在测试运行中您没有关闭连接,然后当任务运行时,另一个进程(应用程序的早期实例)尚未释放资源。
Something hasn't released it's hold on the XML file. You need to figure out what other program is using that resource and ensure that it's connections are closed. It could be that in your test run you don't close your connection, and then later on when the task is run, there's another process (the earlier instance of your app) that hasn't released the resource.
听起来您正在尝试在完全解压缩之前使用 xml 文件。 另外检查一下rie819之前提到的可能性。
如果您发布脚本,我们可以更好地帮助您。
sounds like you are triying to use the xml file before it's fully decompressed. Also check the possibility that rie819 mentioned before.
We could help you better if you post your scripts.
我找到了一种方法来产生我需要的结果。 我从控制台应用程序中取出了两个批处理文件。 我现在有一个任务计划运行一批、控制台应用程序和最后一批。 我收到的两个答案都是正确的,它没有释放 XML,因为控制台窗口在执行过程中打开。 由于它们已被删除,我不再有错误。 谢谢您的帮助。 -Z
I found a way to produce the results I needed. I took the two batch files out of the console app. I now have a task scheduled to run one batch, the console app, and the last batch. Both answers I recieved were correct, it wasn't releasing the XML because of the console windows opening in the middle of execution. Since they have been removed I no longer have errors. Thanks for the help. -Z