I have SSIS package which executes several minutes. It copies data to my PROD database. Package is launched from Sql Server Job. I'd like to take my web site offline during executing of the package. How do I can turn off my web site before execution and then turn on it back automatically?
I use Sql Server 2008 and IIS6.
Thanks
Here is a possible option:
Within the SSIS package:
Create a batch file named StopWebsite.bat with the following command:
iisreset /stop computername
Create another batch file named StartWebsite.bat with the following command:
iisreset /start computername
In the SSIS package, place an Execute Process Task in the Control Flow tab. Call the first batch file StopWebsite.bat from the Execute Process task. This will stop the Internet Information Services (IIS).
Place all your other tasks after the first Execute Process Task.
After all your other tasks in the Control Flow tab, place another Execute Process Task. Call the second batch file StartWebsite.bat. This will start the IIS.
Note that you need to place the batch files in a location where the SSIS package can access them from the production environment.
Within the SQL Server job:
If you don't want to do this in the SSIS package. You need to have three steps in your SQL Server Job.
Step 1 would execute the command iisreset /stop computername as job of type Operating System (CmdExec)
Step 2 would call the SSIS package.
Step 3 would execute the command iisreset /start computername as job of type Operating System (CmdExec)
If you run into permissions issue, make sure that the account (usually it is SQL Server Agent Account) in which the step is being executed has permissions to restart IIS on the remote server. You could also try to use a proxy account that would make use of a domain account credentials, in the following link screenshots 8 - 14 explains how to create a proxy account on job type SSIS Package Execution. You might need to do something similar on the Operating System (CmdExec) job type. How do I create a step in my SQL Server Agent Job which will run my SSIS package?
Replace computername with your actual computer name or IP address of the machine where your website is hosted.
I would say option #2 is easier to maintain.
Hope that helps.
Related
I'm using SQL Server 2008 R2 for Window 8
When I built my webpage, sql server suddently stop and show an error :"Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed. "
Try to fix that problem by searching google. As recommended, I have to delete the folder C:\Users\User\AppData\Local\Microsoft\Microsoft SQL Server Data, but there is no folder with that path
Try another way,I run the below code in SQL Query window:
exec sp_configure 'user instances enabled', 1.
Go
Reconfigure
But it has an error: The configuration option 'user instances enabled' does not exist, or it may be an advanced option.
Help!!! Which way is the better one??? And How can I fix this:Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
You can try this:
Stop all user instance processes of SQL Server running under your local account (open up task manager and look for sqlsrv.exe process and end it)
Delete all files in the %LOCALAPPDATA%\Microsoft\Microsoft SQL Server Data\SQLEXPRESS folder
All be aware that if you are using XP the location will be something like
C:\Documents and Settings\\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS
F5 again
The problem is known issue. SQL Express cannot create a user instance using the set of engine files in your local app data folder, deleting them should allow sql server to recreate them with the correct credentials for you to F5 successfully.
I believe you may not be having SQLExpress installed as directories does not exist. In that case you will need to reinstall the version of SQL Express that was included in the project.
Is there a way to start / stop a windows service of a server in a different network
(not \\<server name>) from an asp.net page?
I tried using ServiceController but it's only work if it's in the same network.
RE: ServiceController How to Start/Stop a Windows Service from an ASP.NET app - Security issues
Anything you can do from command line or powershell can be ran from a page (assuming the app pool user has correct permissions etc)
https://serverfault.com/questions/429426/how-can-i-connect-to-a-windows-server-using-a-command-line-interface-cli
Run Command Prompt Commands
How To: Execute command line in C#, get STD OUT results
Powershell is probably your best bet for managing services on a remote server though this will require the server to allow remote powershell.
Calling Powershell from C# (ASP.NET) - pass custom object?
http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
and of course for the topic of powershell resetting/stopping remote services.
http://www.powershellmagazine.com/2012/08/28/pstip-starting-and-stopping-services-on-remote-computers/
How to start/stop a service on a remote server using PowerShell - Windows 2008 & prompt for credentials?
Google is definitely your friend on this one :)
What is the right approach when users (authenticated domain admins) should be able to start batch jobs (usually exe files) from an IIS (7.x) aspx (c#) page? This is an intranet site. The batch jobs have to run on the web server as Domain Admins. The website pool is executed by network service or some similar restricted account in AD.
Approaches I can think of (and their disadvantages):
1. Start exe file with System.Diagnostics.Process.Start with another account. This feature is disabled in IIS 7.x, how do I allow it?
2. Create a sheduled task and call scheduled task-api. This unmanaged dll is giving VS compiler warnings because it's unsafe to call from managed code.
3. I suppose there's a better approach, because the previous suggestions doesn't appear safe or robust.
I would suggest that you have either a Scheduled Task or Windows Service that polls a common storage repository to see if a batch job should be run - as batch jobs are typically used for long running process.
Your could persist the deatils of which batch file and arguments you want to run from your ASP.NET website into a database (MySQL, Oracle, SQL Server, etc) and then have your Windows Service / Scheduled Task poll against this database at regular intervals.
I agree with Kane. However, if you must do...
http://www.dotnetscraps.com/dotnetscraps/post/Run-a-batch-file-as-a-specific-User-(or-Administrator)-from-ASPNET.aspx
my requirement is as follows. the SSIS and DTS packages are stored on the webserver (not in database) and I need to execute them on click of a button on an ASP.NET web page and be able to abort them (again by user action) if they hang for some reason. user doesn't have access to sql server management studio or enterprise manager. if I choose the third option of executing the package in a job from this link http://blogs.msdn.com/b/michen/archive/2007/03/22/running-ssis-package-programmatically.aspx, then what do I need to install on the WEBSERVER apart from SSIS and DTS runtime libraries for this to work? do I need to install any SQL components on the webserver?
From the link you provided, under option 3 in the "Drawbacks" section: "Agent requires installation of SQL Server engine." Since you chose the option to run as a Sql Agent Job, the SQL Server engine is required to be installed on the webserver to use this option.
I need to create and modify tasks in Windows Task Scheduler on Windows Server 2003 from an ASP.NET web application. The Network Service that the web app runs under is unable to make the changes. It errors with an System.UnauthorizedAccessException exception.
It works fine running from Visual Studio on my desktop.
What permissions do I need to grant an account so that the tasks can be modified from ASP.NET?
The account needs to have read/write permissions to the "Tasks" directory. Here's the path:
%SystemRoot%\system32\Tasks\
Jose's answer solved my problem partially. However, there was an additional problem where Windows Server 2003 didn't like me specifying Local System as the account that the task would run under. It seemed to not like me passing in a null password which is how you specify Local System. I worked around the problem by making a local account on the server for tasks to run under and specifying this new account.
Specifying Local System didn't cause any problem on Windows XP.
Additional info
CACLS TASKS /E /G builtin\administrators:F
According to: https://social.technet.microsoft.com/Forums/lync/en-US/67734412-bb17-42d5-80ff-0edf3147c169/cannot-create-scheduled-task-access-denied