问题
I am trying to find a better way to test our SSIS application, which is used to load data from a file into SQL Server and validate the file data.
I have created a SQL script which can be run to insert 'bad' data into the database tables, and ensure that our validations are performing correctly.
The SQL script:
- loads 'bad' data
- executes the SSIS validations
- ensures the errors in the data were detected
- Outputs a PASS or FAIL
- Deletes the TEST data if passed
Is there anyway I can get this script to be run automatically somehow, for example after someone checks in some code? Should I add it as a stored proc?
I had a look at the Default template Build definition but I couldn't see how to run this SQL script.
回答1:
It doesn't appear that you can do it as part of a checkin based on my 2 minutes of searching.
- How to modify the default Check-in Action in TFS?
- http://msdn.microsoft.com/en-us/library/ms243849(VS.80).aspx
- Can I modify the default Check-in Action in TFS 2012? (pretty picture)
- http://www.codeproject.com/Tips/562994/Perform-a-custom-action-for-Check-in-event-in-Micr
Instead, you'll need to set up a build server to handle the action. Out of the box, MSBuild doesn't have the ability to run a SQL Script so you'll need to snag the MSBuild Extension Pack and leverage SqlExecute
- http://msdn.microsoft.com/en-us/library/ms181712.aspx
- http://msdn.microsoft.com/en-us/library/ms181710(v=vs.90).aspx
- http://msdn.microsoft.com/en-us/library/cc668755(v=vs.90).aspx
- http://www.msbuildextensionpack.com/help/4.0.5.0/html/0d864b98-649a-5454-76ea-bd3069fde8bd.htm
回答2:
The wrong way to do this is using a build server. There are lots of parts to a continuous integration and a build server is really designed for compilation and validation that does not require an instance of your environment. There are two good practices that you can adopt:
- Create a test harness that allows you to load a singe package from your SSIS scripts and test the inputs and outputs. Essentially unit tests. I did this for a customer a few years ago and it worked well.
- Use a release management tool to push out your packages, the data, and everything else that you need. Release Management for Visual Studio can do this easily.
A rule of thumb that I always go buy is if I do not need an instance of anything but in memory objects then all I need is a build server. However if I need an instance of my app then I want to add release management tools to my continuous integration strategy.
回答3:
You can use SQL Server Agent to embed for example your SQL code and you can than run this job from your application.
来源:https://stackoverflow.com/questions/23992656/execute-sql-script-after-ssis-build-or-check-in