I have a sub Application_End in a global.asax file in an asp.net web application
The VB.net code connects to a SQL server database and runs a SQL Server agent job using the SQL command object.
As expected, when I run and close my web app on my development server the job runs just fine.
Ive deployed my application to my production server using the standard "Publish web site" feature in VS 2010. The sub fails to execute on application end in production. Moreover I see no glabal.asax file in the application folder on my web server.
What am I missing here? How can i get this SQL Agent job to run for me in production?
Many thanks ahead of time for your help.
jhh
here's my code
==========================
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
'ADO.net code to connect to SQL server and use a command object to execute a SQL afent Job
Dim SQLStr As String
Dim ConnString As String
'Connstring = Server Name, Database Name, Windows Authentication
ConnString = "Data Source=DH5306\DMSSURG3;Initial Catalog=NSQIPSampling;Integrated Security=True"
Dim SQLConn As New SqlConnection() 'The SQL Connection
Dim SQLCmd As New SqlCommand() 'The SQL Command
SQLConn.ConnectionString = ConnString 'Set the Connection String
SQLConn.Open() 'Open the connection
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
SQLCmd.CommandText = SQLStr 'Sets the SQL String
SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only
SQLConn.Close() 'Close the connection
End Sub
jhh
Don't forget to mark as answer if this post was helpfull. Thanks!
I think the global.asax file gets compiled into the app_code folder, and that is why you don't see it. I would try moving all source code files to the production server and running the site of source code and see what happens.
Also, are you sure that the correct permissions are set on the database to execute those stored procedures?
I don't understand why after you help someone, they don't mark your post as the answer. What's up with that???
As expected, when I run and close my web app on my development server the job runs just fine.
It runs because you are restarting the local development server. But in the production, it does not happen unless you restart IIS manually or by editing the web.config file (Which result in restarting the website).
LostArrow
Ive deployed my application to my production server using the standard "Publish web site" feature in VS 2010. The sub fails to execute on application end in production.
It won't run when the user close the web application. It will only be run when the application stops/restarts on the server side, not the client side. If you are expecting to run the SQL job when the user close the application, best event to fire it would
be Session_End event in global.asax file.
LostArrow
Member
59 Points
38 Posts
sub application end won't execute on production server
Nov 30, 2012 01:30 PM|LINK
I have a sub Application_End in a global.asax file in an asp.net web application
The VB.net code connects to a SQL server database and runs a SQL Server agent job using the SQL command object.
As expected, when I run and close my web app on my development server the job runs just fine.
Ive deployed my application to my production server using the standard "Publish web site" feature in VS 2010. The sub fails to execute on application end in production. Moreover I see no glabal.asax file in the application folder on my web server.
What am I missing here? How can i get this SQL Agent job to run for me in production?
Many thanks ahead of time for your help.
jhh
here's my code
==========================
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
'ADO.net code to connect to SQL server and use a command object to execute a SQL afent Job
Dim SQLStr As String
Dim ConnString As String
'Connstring = Server Name, Database Name, Windows Authentication
ConnString = "Data Source=DH5306\DMSSURG3;Initial Catalog=NSQIPSampling;Integrated Security=True"
SQLStr = "EXEC MSDB.dbo.sp_start_job @Job_Name = 'SQLAgentCLARITYOptimeCases'"
'SQLStr = "EXEC MSDB.dbo.sp_start_job @Job_Name = 'testjob'"
Dim SQLConn As New SqlConnection() 'The SQL Connection
Dim SQLCmd As New SqlCommand() 'The SQL Command
SQLConn.ConnectionString = ConnString 'Set the Connection String
SQLConn.Open() 'Open the connection
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
SQLCmd.CommandText = SQLStr 'Sets the SQL String
SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only
SQLConn.Close() 'Close the connection
End Sub
Don't forget to mark as answer if this post was helpfull. Thanks!
javedwahid
Participant
1687 Points
471 Posts
Re: sub application end won't execute on production server
Nov 30, 2012 11:31 PM|LINK
I think the global.asax file gets compiled into the app_code folder, and that is why you don't see it. I would try moving all source code files to the production server and running the site of source code and see what happens.
Also, are you sure that the correct permissions are set on the database to execute those stored procedures?
Ruchira
All-Star
42975 Points
7025 Posts
MVP
Re: sub application end won't execute on production server
Dec 01, 2012 12:03 PM|LINK
Hello,
It runs because you are restarting the local development server. But in the production, it does not happen unless you restart IIS manually or by editing the web.config file (Which result in restarting the website).
It won't run when the user close the web application. It will only be run when the application stops/restarts on the server side, not the client side. If you are expecting to run the SQL job when the user close the application, best event to fire it would be Session_End event in global.asax file.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.