I suppose it is a little different for me, since I have always had access to
the database as well as the application code.
I always like to put as much logic in the database as possible, simply
because I can change the stored procedure without needing to repackage and
deploy the application. It also makes for much cleaner code, although the
tradeoff is the programmer cannot see what is going on in the database.
This last piece can be either a pro or a con, depending on how knowledgeable
and involved the programmer is with the database code.
The other benefit is that it is much simpler to debug a single stored
procedure call than multiple lines of concatenated text.
"John A. Bailo" <ja*****@texeme.com> wrote in message
news:_s********************@speakeasy.net...
He could do that, or just parameterize his string sql query.
You should never put values in quotes in a string.
Use @vars and replace them with sql params, just like in a stored
procedure.
Putting logic like this in a stored procedure isn't alway to my liking
(although it seems to be Gospel in the MS camp).
It's perfectly reasonable to use queries in ado, and it gives the
programmer far more control than having to go back and forth to sprocs
and code.
Jim Underwood wrote: Rather than using SQL like this just build a stored procedure that
contains the logic. Then call the stored procedure from your code. Always makes
for cleaner and safe code this way.
"John Scott" <jo*******@despammed.com> wrote in message
news:36**********************************@microsof t.com...
Ok...here we go...
I am trying to manually run an SQL server back up job from c#. Here is
asnippet of my code to begin the process:
string strSQL = "USE msdb " +
"\n if exists(select * from sysjobs_view where name = 'TempBackupJob') "
+"\n EXEC sp_delete_job @job_name = 'TempBackupJob' " +
"\n GO";
newDB.Command(strSQL);
This command exceptions with an "Incorrect syntax near 'GO'".
Now, when I put the EXACT same query into Query Analyzer like this:
USE msdb
if exists(select * from sysjobs_view where name = 'TempBackupJob')
EXEC sp_delete_job @job_name = 'TempBackupJob'
GO
the command executes without any errors.
Is there something I'm missing with newline characters? I also tried
using
\r\n instead of just \n to separate the lines...that didn't work either.
Any help would be greatly appreciated.
--
Thanks,
John Scott.