我想创建一个移动文档并根据 SQL 查询可以使用的表重命名它的服务。我有相同的代码,它使用按钮按下并执行需要完成的操作。但是,当我运行该服务时,它会看到文档,然后它会获取文档的 ID,但它会在 SQL 查询处停止并且不会继续。
如果我取出 SQL 调用,它会移动文档并将它们重命名为我可以分配的通用名称。我想自动执行此操作并使用 SQL 查询。
public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
{
eventLog1.WriteEntry("Monitoring the System.", EventLogEntryType.Information, eventId++);
try
{
string dest = @"F:\Temp2\";
foreach (var file in Directory.EnumerateFiles(@"F:\Temp\"))
{
List<Document> ld = new List<Document>();
SQLImport si = new SQLImport();
string fileName = Path.GetFileName(file.ToString());
ld = si.getDocID();
int docID = ld[0].DocID;
int newDocName = docID + 1;
int accountNumber = 1;
string docStatus = "New Import";
string fileName2 = docRetrieval.doc(newDocName.ToString());
string newdocName = fileName2 + ".pdf";
string nameChange = file.Replace(fileName, newdocName);
si.setDocumentInformation(newDocName, accountNumber, dest, docStatus);
string destFile = Path.Combine(dest, Path.GetFileName(nameChange));
if (!File.Exists(destFile))
File.Move(file, destFile);
}
}
catch (Exception)
{
eventLog1.WriteEntry("The process failed: {0}");
}
}
SQL 导入/导出:
public List<Document> getDocID()
{
using (IDbConnection connection = new SqlConnection(helper.CnnVal("WorkflowConfiguration")))
{
var output4 = connection.Query<Document>($"Select DocID From [Workflow Creation].[dbo].[CustomerDoc] ORDER BY DocID DESC").ToList();
return output4;
}
}
什么被忽视了?
我通过将登录Local System
身份从登录更改为有权访问 SQL 服务器的帐户解决了该问题。源于@FlyDog57 的回答
谢谢你的帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句