CLR SQL Stored Procedures Testing with Unit Test Project - sql

I'm just getting into using VS2008 to write clr stored procedures for SQL 2008. When writing c# code I am used to having a separate 'Test Project' where I would place all my unit testing code, however it appears at first blush that I can't have the same setup with a clr sql project with stored procedures. It 'feels' like this can be done, and I'm missing a couple of configuration parameters, but I'm not sure what those might be.
I am using
Visual Studio 2008
MS Test
MS SQL 2008
My requirements are:
debug the stored procedure in the visual studio debugger
have a bunch of unit test to test the stored procedures
Does anyone know how I can have the unit test project properly depoly the stored procedures to the server, connect up to the sql server, and allow me to step through the unit test to the stored procedures that are sitting on the server?
****UPDATE****
Thank you to everyone for the answers so far, however they are not excatly what I'm looking for.
Mark Seemann's answer below is an interesting approach that I did not know about, and I will certainly use when it comes to resetting my database to a known state. However, I am looking to debug CLR stored procedures, and it doesn't appear Mark's method will allow me to step from my unit test project, through to the SQL server, and debug the code sitting on the server.
I am looking to actually debug the C# sitting on the server, much like the solution pho3nix listed below. However, using this standard approach you need to write your test scripts using a 'Test.sql' file and not using a unit test project from within Visual Studio.
I hope I can have two projects in my solution, one for my CLR stored procedures and one for my unit test project. When I want to run my tests in my unit test project I hope that all of the changes made to my CLR stored procedure project will be published to the server, the test project will start executing, and if I set a break point in the CLR stored procedure when the unit test begins to test that stored procedure it will break on the server and I can then step through the code.
The closest solution I have found so far is by Alex Kuznetsov and Alex Styler, however using this solution I can not step through to the SQL server.
****UPDATE 2****
This is more of a 'bump' to bring this question back up...I've still had no luck stepping to the SQL server from the unit tests. Any other thoughts?

You have to enabled SQL/CLR debugging on the connection before being able to debug your code.
in order to do that, follow the instructions here
http://msdn.microsoft.com/en-us/library/ms165039(VS.80).aspx
Note that when you debug your C# SP, all the managed threads in the SQL server will suspend during your debugging
Hope this helps.

When create a project i have a treeview node with database and an item named SQL Server Project.
alt text http://img514.imageshack.us/img514/8523/81345560.jpg
Next when project template is created i get Test Scripts (Test.sql) where i can test all my SQL Server CLR classes, using common sql procedures and commands.
alt text http://img17.imageshack.us/img17/7826/38591345.jpg
With this you can have an development interface for CLR with debug. Test.sql is like an Unit Class for CLR classes.
PS. Don't forget active CLR in your SQL Server Configuration.

I wrote pretty extensively on this subject some time ago. I always implement my data access components in a TDD fashion. Take a look at the post in the link - the article itself may not provide you with the best overview, but you can also download the sample code and inspect it at your own leisure.
I should think it meets all your requirements.

Related

How can I call a PRO*C program directly from PL/SQL?

I couldn't find a similar question here.
I have a PRO*C program named pro_c.pc. How can I call and execute this in a piece of PL/SQL code?! Could someone give me a simple example?!
You can link external libraries (Windows DLL or UNIX ".so" files) to Oracle and then make them callable via PLSQL. This has been around at least since Oracle 8i.
This though requires DBA privs on the server to set this up, and is probably not a recommended approach these days .... but useful for crunching huge data.
See here for more details.
Calling a actual program directly, as opposed to a library function from PLSQL would be done indirectly via DBMS_SCHEDULER as #Justin suggested as the easiest way, creating a program with the PROGRAM_TYPE as EXECUTABLE. See here for more info.
A couple of things to note when doing this, the program will run as the (assuming UNIX) "oracle" user - bringing with it some security considerations, e.g. if the program creates a file it will be created as owned by oracle, and so might not be accessible to an "application" user. The program will run on the Oracle database server.

Oracle SQL Automation

I have a question regarding Automation.In my project we have 35 SQL scripts with same logic,same scripts for all those, with only 4 parameters different how can i automate these in TOAD for Oracle?
Depending on your version of Toad, there could be a 'Automation Designer' under the 'Utilities' menu item. This will allow you to run scripts automatically, based on a bit of logic. It also supports running with parameters.
The tool 'Toad for Data Analysts' can also be used to model automated scripts, and run them with specific parameters.
If you have any of these tools available, I would suggest giving them a try, or at least read up on their documentation. If you don't have access to these, let me know so I can try and think of a different solution.

SSIS 2012 - Error output columnname

We are building a SSIS package for a customer where a lot of conversion checks happen in 1 dataflow task. We output any errors to a script that generates a new record for our Error-table. That error-table could then be consulted to check if any errors occurred.
We are aware that there are a few scripts and components out there to retrieve the real columnname from an error-output. But those are all for 2008 R2 or lower.
Secondly, we compared our 2012 xml with the 2008 R2, 2008 xml and there isn't any sign anymore of a lineageID, so we think that the scripts and components above will not function anymore.
Weird thing is though that in our designer in the advanced edit screen, we can see our lineageId's. Sadly, we fear that those are generated on runtime and can be different every run. So we can't script against those to retrieve the real columnname.
Anybody has any tips or tricks to resolve this?
Kind regards,
Tom
Benny Austin's solution
This provided me with an answer. Do read the comments about the package though, you might need to fiddle somethings before it works. But eventually it does.

Anyone had any luck integrating SQL unit tests to run with CI build tool?

Goal is to run a few queries against a database on each new build? Has anyone had any luck without having to put sql in java classes or creating entire new schemas to hold stored procs? Ideally you can include some SQLs in separate files that get run as soon as the build completes.
Might be using maven,bamboo but would love to hear any experiences/successes/difficulties that people have encountered.
You don't say what tools you use for writing you SQL unit tests. If you're using Steven Feuerstein's utplsql tool you should read this artcle on Continuous Integration with Oracle PL/SQL, utPLSQL and Hudson. And even if you're not it might provide some useful insights.
Maybe Team City (Jetbrains) is what you're looking for. It has various build runners, including but not limited to Ant, MS Build, NUnit, Maven and Command Line.
Just configure a TC-project to listen to your svn/git/hg repository for changes, then run a build: first compilation and if successful then Maven (or whatever). Or which-ever way you want to do it.
/mikkel

SQL Server Version Updating Tables

I am part of a software development company looking for a good way to update my SQL Server tables when I put out a new version of the software. I know the answer is to probably use scripts in one form or another.
I am considering writing my own .NET program that runs the scripts to make it a bit easier and more user-friendly. I was wondering if there are any tools out there along those lines. Any input would be appreciated.
Suggest you look at Red_gate's SQlCompare
What kind of product are you using for your software installation? Products like InstallShield often now include SQL steps as an option for part of your install script.
Otherwise, you could look at using isql/osql to run your script from the command line through a batch file.
One of the developers where I'm currently consulting wrote a rather nifty SQL installer. I'll ask him when he gets in how he went about it.
I am using Red Gate's SQL Compare all the time. Also you need to make sure to provide a rollback script in case you need to go back to the previous version.
Have a look at DB Ghost Packager Plus.
Packages your source database and the compare and sync engine into a simple EXE for deployment. The installer EXE will automatically update any target schema to match the source on-the-fly at installation time.
Red Gate's SQL Compare to generate the change script, and Red Gate's Multi Script to easily send it to multiple SQL databases at the same time.