Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I developed a vb.net application which extract data from oracle db and post in existing Excel-2013 file. This application runs perfect either I run it from .net frame work or direct Exe file but When I schedule it in Window Scheduler it remains in Running Status and does not show in Task manager while if i run it manually it shows. Please suggest how i can run this application from windows schedule. I developed it VStudio-2015.


What I have tried:

I tried it on different OS like Windows-2008 R2 Service Pack-1 and Windows-10 but problem facing same.
Posted
Updated 29-Jul-20 3:45am
v2
Comments
Garth J Lancaster 29-Jul-20 7:30am    
I'm sure you'd have added logging to the program
and be trapping any exceptions
and be checking the Windows Event Logs
and have fully qualified the paths to your excel file

since you don't show any code its going to be hard to help
Member 14901906 29-Jul-20 9:35am    
This is my complete code with dummy IPs, and Email

Imports System.Data.OracleClient
Imports System.Data.OleDb
Imports Microsoft.Office.Interop
Imports System.Xml
Imports System.Data
Imports System.Net.Mail
Imports System.IO
Public Class Form1
Public con As OleDb.OleDbConnection
Public fileReader As String
Public da As New OleDb.OleDbDataAdapter
Public dt As New DataTable
Public ds As DataSet
Public sqlkd1 As String
Public sqlkd2 As String
Public sql As String
Public sqlb, sqle, sqlh, sqlf, sqlm, sqlch, sqlr, sqlp, sqla, sqlk, sqll, sqlbm As String

Private Sub Form1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try

sqlkd1 = "delete from inv_dcs_udf "

sqlkd2 = "INSERT INTO ABC "


sqlb = " select * fROM DEF "

sqlh = " select * FROM GHI "

sqlf = " select * FROM JKL "

sqlbm = " select * FROM MNO "

sqlm = " select * FROM PQR "

sqlch = " select * FROM STU "

sqlr = " select * FROM UVW "

sqlk = " select * FROM XYZ "

sqll = " select * FROM ABC2 "

sqle = " select * FROM ABC3 "

sqlp = " select * FROM ABC4 "

sqla = " select * FROM ABC5 "


For count1 As Integer = 1 To 10
If (count1 = 1) Then
fileReader = "172.10.140.106"
ElseIf (count1 = 2) Then
fileReader = "172.20.140.108"
ElseIf (count1 = 3) Then
fileReader = "172.20.140.109"
ElseIf (count1 = 4) Then
fileReader = "172.10.140.107"
ElseIf (count1 = 5) Then
fileReader = "172.10.140.203"
ElseIf (count1 = 6) Then
fileReader = "172.10.140.201"
ElseIf (count1 = 7) Then
fileReader = "172.20.140.204"
ElseIf (count1 = 8) Then
fileReader = "172.30.140.202"
ElseIf (count1 = 9) Then
fileReader = "172.40.140.6"
ElseIf (count1 = 10) Then
fileReader = "172.20.140.150"
End If
''fileReader = "172.20.140.108"
fill_dataadopter()
Next
'' Me.Close()
Try
PopulateSheet(dt)

Timer1.Interval = 100000
Timer1.Start()
Timer1.Stop()

email_report()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
dt.Dispose()
End Try

Catch error_t As Exception
MsgBox(error_t.ToString)

End Try
Me.Close()
End Sub
Public Function connection_funcation() As OleDb.OleDbConnection

Return New OleDb.OleDbConnection("Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + fileReader + ")(PORT=1521)))(CONNECT_DATA=(SID=rproods)(SERVER=DEDICATED)));User Id=reportuser;Password=report")
End Function
Public Function fill_dataadopter()
con = connection_funcation()
con.Open()
Dim selcmd1 As New OleDbCommand(sqlkd1, con)
selcmd1.ExecuteNonQuery()
Dim selcmd2 As New OleDbCommand(sqlkd2, con)
selcmd2.ExecuteNonQuery()

If fileReader = "172.20.140.150" Then
For count1 As Integer = 1 To 3
If (count1 = 1) Then
da = New OleDb.OleDbDataAdapter(sqle, con)
da.Fill(dt)
ElseIf (count1 = 2) Then
da = New OleDb.OleDbDataAdapter(sqlp, con)
da.Fill(dt)
ElseIf (count1 = 3) The
Member 14901906 29-Jul-20 8:00am    
I used Task Scheduler on Window-10 and same on Windows-2008 Server with setting "Run whether user is logged on or not"
Maciej Los 29-Jul-20 8:10am    
Please, read OriginalGriff's answer.

Probably it's a problem with access permissions: an app run from the scheduler can only work if the user is logged in, or if it has no interface. If you selected "Run whether user is logged on or not" then it will only run from the Scheduler if it does not interact at all - any attempt to create any sort of user interface will give the symptoms you describe.

Think about it: if it can run when the user isn't there and has a UI, it's bypassing login protocols and security will not permit that. So if you app has a UI, it can't be set to run when the user isn't logged in (as the user could be logged off while it starts for example).
 
Share this answer
 
Comments
CPallini 29-Jul-20 7:45am    
5.
Maciej Los 29-Jul-20 8:10am    
5ed!
This should have been written as a Console app, not a Windows Forms app. Scheduled jobs are usually not user-interactive, so a Windows Forms app is going to present the symptoms you describe.

Look at your code. You've got a couple of MessageBox calls in there. These will show a dialog box the user has to click OK on to dismiss. Until that happens, your code will sit there, "running" forever. Scheduled jobs typically run in the background with no user interaction, so the app sits there, waiting for input that will never happen.

Recreate the app as a Console app and it'll work better. Also, if you're going to show messages to the user, log them somewhere instead, like the Application Event Log, or a file in a well-known location.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900