If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Problem With MS Word DCOM on ASP Page

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-06, 09:40
Mcphee78 Mcphee78 is offline
Registered User
 
Join Date: Nov 2006
Posts: 3
Problem With MS Word DCOM on ASP Page

Hi there

I have a problem with winword.exe on my server. i have an asp page which populate a word template on my web server using bookmarks which works fine
but for some reason it does not close the winword.exe on the server after the document has been populated and saved and i end up with lot of these running in the server taskmanager which i have to close down manually what make this even stranger is that when i test it on my laptop the winword.exe are close after the page has ran

please see my code below

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #INCLUDE FILE = "../../DB/DBConnect.asp" -->
<% Session.LCID = 2057 %>
<%
On error Resume Next
Server.ScriptTimeout = 100000
Dim PrimKey

PrimKey = Request.QueryString("PrimKey")

Dim rs
set rs = Server.CreateObject("ADODB.Recordset")

SQL = "SELECT * FROM tbl_ASR " & _
"WHERE PrimKey = '" & PrimKey & "';"

rs.Open SQL,objConn,2,3

Dim FileName
FileName = rs("FirstName") & "_" & rs("Surname") & "_" & rs("Payroll") & "_" & rs("CostCentre")

Dim wdApp
set wdApp = Server.CreateObject("Word.Application")

'Server
wdApp.visible = true

Dim wdDoc
strPath = Server.MapPath("\Transactional_Services\Subsites\A SR\Template\ASR.dot")

set wdDoc = wdApp.documents.open (strPath)

If wdDoc.Bookmarks.Exists("Name") Then
wdDoc.Bookmarks("Name").Range.Text = " " & rs("FirstName") & " " & rs("Surname")
End IF

If wdDoc.Bookmarks.Exists("JobTitle") Then
wdDoc.Bookmarks("JobTitle").Range.Text = " " & rs("JobTitle")
End IF

If wdDoc.Bookmarks.Exists("PayrollNumber") Then
wdDoc.Bookmarks("PayrollNumber").Range.Text = " " & rs("Payroll")
End IF

If wdDoc.Bookmarks.Exists("Directorate") Then
wdDoc.Bookmarks("Directorate").Range.Text = " " & rs("Directorate")
End IF

If wdDoc.Bookmarks.Exists("Location") Then
wdDoc.Bookmarks("Location").Range.Text = " " & rs("Location")
End IF

If wdDoc.Bookmarks.Exists("CostCentre") Then
wdDoc.Bookmarks("CostCentre").Range.Text = " " & rs("CostCentre")
End IF


wdDoc.saveas Server.MapPath("\Transactional_Services\Subsites\A SR\ASR_Documents\" & FileName & ".doc")

wdDoc.Quit
wdDoc.Close
Set wdDoc = Nothing

wdApp.Quit
wdApp.Close
Set wdApp = Nothing

rs.close
objConn.close
set rs = Nothing
set objConn = Nothing

Response.Redirect("ASR_Documents/" & FileName & ".doc")

%>

If any body can give me any hint tip or knows how to solve this problem PLEASE HELP
Reply With Quote
  #2 (permalink)  
Old 11-06-06, 12:57
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
DO NOT USE OFFICE AUTOMATION ON A WEB SERVER.

It is very, VERY bad ju-ju.

As you've noticed, the second you start threading out automation you tread into unmanaged code territory and end up with bizarre behavior if you have more than one user. I would very strongly recommend you find a solution that does not involve automation on your webserver.
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #3 (permalink)  
Old 11-07-06, 02:38
Mcphee78 Mcphee78 is offline
Registered User
 
Join Date: Nov 2006
Posts: 3
Teddy

What would you recommend then instead of office thats just what i have avilable where i work
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On