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);
}
}
}
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.