views:

112

answers:

3

I'm deploying a web site and I need to run large TSQL scripts contained in a single file in a production server where I don't have full access to SQL Server console and I can't connect remotely. The scripts is a mixed of table, stored procedures and views creations. All I can do is to run 1 group of TSQL sentences, like the ones for a stored procedure.

I have two options: to parse the file manually looking for GO's sentences and run each block of sentences before that GO, or to do the same task but with a tool. Using a tool I will be very fast doing the task, but I don't know any tool such that.

Do you know any tool that I can use?

I think it must be something like a control, with an editor where I will paste or load the scripts to run, and it will be able to parse and run them in sequence, like the Microsoft SQL Server Management usually does.

A: 

You could check out some articles on CodeProject on the topic and maybe use one of those tools / component for your needs?

Most of those come with full source and could also serve you as a starting point for a custom version of your own.

Marc

marc_s
A: 

If those don't work, it's pretty easy to write such a tool yourself. Just use Regex.Split to split the text on the GO lines, then loop, calling ExecuteNonQuery for each section.

John Saunders
Heads up! If you go this route make sure "GO" is not embedded in a string or that you don't have a column named GO_time. Here is a fairly safe regex to use. "^\GO\w*$"
jms
+1  A: 

hi, you got many options

  • usually i create stored procedure in sql management studio then save it as string, then use linq2sql to execute the stored procedure, works very well.

  • use sql server smo object where you can really do mostly many things like creating DBs, tables, it is really cool, i create 1 page on my site and use it to update DB with it. here is a good link for that http://www.sqldbatips.com/showarticle.asp?ID=34

  • you can use Redgate SQL data compare, and Compare. they rock really to synchronize DBs, it have saved me a lot of time and it is super easy, highly recommended really.

hope this helps.