If you want to execute sql scripts via sqlcommand programmatically, then you need to open the file and read it line by line. As you pass each line, append it to the current batch string builder and when you hit a line that after trimming is GO, get string builder ToString and execute that batch. Clear the current batch and keep going edit: second part of question As far as the parameters go, you can either replace them as part of parsing and executing or you could pull duties like creating the DBs out to C# code.As a preference, I've always kept the sql scripts runnable by ssms and sqlcmd by developers even though they happen to be run by C# code as part of the deployment.
So that means, I wouldn't make up any special tokens that only your code understands. You could leave as is in your question, replace them and above that in the script, have the variables declared and commented out with -- so developers can easily work in ssms.
If you want to execute sql scripts via sqlcommand programmatically, then you need to open the file and read it line by line. As you pass each line, append it to the current batch string builder and when you hit a line that after trimming is GO, get string builder ToString and execute that batch. Clear the current batch and keep going.
Edit: second part of question As far as the parameters go, you can either replace them as part of parsing and executing or you could pull duties like creating the DBs out to C# code. As a preference, I've always kept the sql scripts runnable by ssms and sqlcmd by developers even though they happen to be run by C# code as part of the deployment. So that means, I wouldn't make up any special tokens that only your code understands.
You could leave as is in your question, replace them and above that in the script, have the variables declared and commented out with -- so developers can easily work in ssms.
Ok, that's certainly one way to tackle it, thanks! This only answer parts of my question, though, how to handle parameters is still of interest. I suppose - following this approach - since I'm already parsing the file, I might as well modify the parameters into something understandable by SqlCommand as well... – havardhu Sep 5 at 12:16 You can either replace those as part of parsing and executing the batch or you can move the dynamic portions like creating the db (device directory etc...) out to C# code.As a personal preference I always like the sql scripts to be scripts that can be run in SSMS or sqlcmd even though they also happen to be run by the deployment code.
– bryanmac Sep 5 at 12:39 Yeah, that's one of my objectives; keeping a single script that can be utilized both by the config tool and via sqlcmd etc. – havardhu Sep 5 at 13:00.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.