jwcolby
jwcolby at colbyconsulting.com
Tue Dec 1 16:53:55 CST 2009
As previously mentioned, over the last couple of years I have built up a set of stored procedures which perform TSQL. I then run sets of these stored procedures to perform processes. The TSQL is always dynamic. As an example a stored procedure might build a table, with boilerplate field names and data types, but a passed in database and table name. Inside of the stored procedure I build up the correct SQL to create the table in the database specified, with the name specified. Another stored procedure might create in index, with boilerplate field names, but a passed in database and table name. Again the stored procedure builds up the TSQL statement to create the index in the correct db and table. I already have these stored procedures debugged and working and have been using them in sets to perform "big picture processes" for quite some time, but the whole "execute a stored procedure" using a command object, parameter objects in a parameter array, interpreting the parameters etc just seems so... 1950s. I feel like I am flipping switches on the front panel of a computer in a 50s sci-fi movie as a tape reel spins madly in the background. Now that I am moving to C# I am wondering if this is required any more. Can C# execute TSQL directly somehow? Can I assemble this boiler plate plus database / table kind of thing into a TSQL statement directly in C# and then somehow tell SQL Server to execute that TSQL? I understand the "SQL optimization" thing but it seems like (not sure here) that because the TSQL is dynamically constructed in the stored procedure, the whole "optimization" thing goes right out the window. If I can execute TSQL directly from C#, what can I get back? Rows affected? Error codes? And how? As it stands I am happily flipping switches, tape reels whirring, exporting data for address validation. This is good, I am happy, but ... -- John W. Colby www.ColbyConsulting.com