Re: .Net Equivilant for sqlcmd or osql



I second this. Parsing on the semicolon is not the way that
applications like SQL Management Studio work.

Also, you do not have to strip the comments, it works just fine,
assuming you have carriage returns and the like.

Basically, attach a StreamReader to the FileStream that is opened to the
script. Read EACH line into a string buffer. If the line contains GO and
ONLY GO, then send everything that you have in the buffer (as you add each
new line, remember to add the newline back to the buffer). Then, clear the
buffer, and continue reading.

We've done the exact same thing where I work to take the scripts that
you would use in SQL Management Studio and execute them without running it.

--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Alberto Poblacion" <earthling-quitaestoparacontestar@xxxxxxxxxxxxx> wrote
in message news:%23rixAKN7IHA.2336@xxxxxxxxxxxxxxxxxxxxxxx
"Harry Keck" <HarryKeck@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0C64CF08-4CBC-4388-A166-0EBABA32C4A6@xxxxxxxxxxxxxxxx
No, executing a DBCommand does not allow sql batches. My files are
either
create scripts for procedures or tables. When I use a DBCommand on a
statement with more than one command, I get an exception. Osql and
sqlcmd
allow execution of batches containing mulitple statements.

There's a trick: Read your script file and split it on the GO
statements. Each piece between two "GO"s can be sent to the server by
means of an ExecuteNonQuery. Besides splitting on the GOs, I believe that
you also have to strip the comments, which you can do by reading the file
line by line and removing everything from "--" to the end of each line.



.



Relevant Pages

  • Re: Creating script support for console application
    ... After mapping the file into memory, you may want to allocate a new buffer ... Of course, a decent script will keep track of line-numbers, so syntax errors ... > commands that tell the program where to BREAK, LOOP, START. ... > thinking of putting each line in an element of an array. ...
    (microsoft.public.vc.language)
  • pyodbc.Error Crash
    ... I believe this bug is also related to the other problem I just reported. ... DB = Microsoft Access XP ... # or buffer length ') ... The broke.py script has 4 select statements but only one is executed. ...
    (comp.lang.python)
  • Re: Numeric or character ?
    ... > anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel) wrote: ... >> when the script happens to do mass IO via STDOUT. ... the buffer just doesn't fill up so much. ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: Tri-x, HP5 and XTOL
    ... > Developers tend to be hostile to many pH electrodes but ... There was 'pH Strip': a coil of paper in a plastic case. ... but then the Xtol _is_ broke ... ... I can't see how anything would upset the buffer ... ...
    (rec.photo.darkroom)
  • Re: A couple of SED questions
    ... with the shell script, not the sed script. ... There is a buffer - I think it is called the hold buffer - accessed with G, H, X and other commands. ... You may be using a version of sed which views end of line as the third s command delimiter. ...
    (comp.unix.shell)

Loading