Word应用程序不会在服务器上关闭 [英] Word applications wont close on server

查看:112
本文介绍了Word应用程序不会在服务器上关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天所有

我手上有点头疼。

以下代码在我的服务器上运行,它确实适用于它的目的。



Good day all
I have a bit of a head scratcher on my hands.
The following code runs on my server and it does work for what it is intended.

public void RenderWithData(string strcaseno, string strdocpath, string strdocsp, string stramnt)
{
	Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application[];
	string suffix = Convert.ToString(DateTime.Now.Minute + DateTime.Now.Millisecond);
	string sourceFileName = System.Web.HttpContext.Current.Server.MapPath(strdocpath);
	string destFileName = System.Web.HttpContext.Current.Server.MapPath("~/Cache/" + ActiveLogin.Login + Session.SessionID.ToString + suffix + ".doc");
	Word.Document docDepetal = new Word.Document();
	FileInfo objFileInfo = default(FileInfo);

	try {
		File.Copy(sourceFileName, destFileName);

		SqlSingleQuery cmd = new SqlSingleQuery(strdocsp);
		cmd.AddInt("@USERID", ActiveLogin.UserID);
		string ParameterName = "value0";
		cmd.AddVarChar(ParameterName, 50, strcaseno);
		cmd.AddMoney("@NEWCONSENT", stramnt);
		cmd.Execute();

		docDepetal = appWord.Documents.Open(destFileName);

		Word.Bookmarks MyBookMarks = docDepetal.Bookmarks();


		foreach (string bookmark in cmd.Columns.Keys) {
			MyBookMarks.Item(bookmark).Range.Text = cmd.Columns.Item(bookmark).ToString();
		}


		docDepetal.Protect(Word.WdProtectionType.wdAllowOnlyComments, false, "password");
		docDepetal.Save();
		docDepetal.Close();
		appWord.Quit();
		Marshal.FinalReleaseComObject(appWord);
		appWord = null;
		objFileInfo = new FileInfo(destFileName);
		DisplayDownloadDialog(objFileInfo);

	} catch (Exception ex) {
		ShowErrorMsg(ex.Message);
	} finally {
		if (appWord != null) {
			if (docDepetal != null) {
				docDepetal.Close();
			}
			appWord.Quit();
			Marshal.FinalReleaseComObject(appWord);
		}

		if (File.Exists(destFileName)) {
			File.Delete(destFileName);
		}
	}
}





现在我的问题是每隔一段时间就会出现一次。 exe进程不会在服务器上关闭,之后打开的每个其他winword.exe进程也不会关闭。然后,由于以下错误导致从iclassfactory创建具有clsid {00020906-0000-0000-c000-000000000046}的com组件的实例失败:8001010a。每次发送新请求以创建文档时显示的错误。



我想知道在这段代码中我是否可以采取不同的做法解决这个问题。



非常感谢任何帮助,并提前感谢你。



Now my problem is every once in a while the winword.exe process will not close on the server, the every other winword.exe process that opens after that will not close either. This then results in a "creating an instance of the com component with clsid {00020906-0000-0000-c000-000000000046} from the iclassfactory failed due to the following error: 8001010a." error that is displayed each time a new request is sent to create a document.

I would like to know if there is something I can do differently in this code that would resolve this issue.

Any help is greatly appreciated and thank you in advance.

推荐答案

运行Word在服务器上只是一个非常糟糕的主意。它是一个交互式程序,可以挂在服务器上,因为它显示一条消息,例如,如果您确定要关闭文档而不保存。因为服务器上没有交互式用户,所以没有人对该消息做出响应,而且只有有人这样做才能继续等待。有一些替代组件可以更好地在服务器上使用。



http://support.microsoft.com/ kb / 257757 / zh-CN [ ^ ]



祝你好运!
Running Word on a server is just a very bad idea. It is an interactive program that can for example hang on the server because it shows a message for example if you are sure you want to close the document without saving. Because there is no interactive user on the server, nobody is responding to that message and word just keeps waiting for until somebody does. There are alternative components that would be better to use on a server.

http://support.microsoft.com/kb/257757/en-us[^]

Good luck!


有时组件有问题。尝试重新安装特定组件可能会修复它。
sometimes a component has some problem. Try re-installing the particular component might fix it.


这篇关于Word应用程序不会在服务器上关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆