Tuesday, March 20, 2012

Running sql script from Setup deployment .NET

Posted - 04/21/2004 : 09:26:34
----
Friends
I want to run sql script for creating of database which
contains tables and stored procedures by setup and deployment project
in VS.NET. I have created customaction and passing the string
containing script to the ExecuteNonQuery() procedure to run the script
The problem is where ever GO statement is there in the script it
is giving problem. I read somewhere that
" Your script must not include any go statements. These are used onl
by Query Analyzer or the osql.exe utility. If they are present in you
script when using it with ADO.NET (as in this demo), then th
ExecuteNonQuery will fail."
If i remove Go from the script then it is giving exception again
telling that "Incorrect syntax near the keyword Procedure"
where ever create Procedure statement is there
Please help me in this regard
-
sudhape
----
Posted via http://www.webservertalk.co
----
View this thread: http://www.webservertalk.com/message190433.htmSudhapec
from BOL: CREATE DEFAULT, CREATE PROCEDURE, CREATE RULE, CREATE TRIGGER, and CREATE VIEW statements cannot be combined with other statements in a batch. Batches are delimited by the keyword GO in a script, hence your problem. I guess you could create multiple scripts - one main one and a separate script for each of the above commands. Another (easier) alternative would be to not use ADO.NET for this step, but OSQL. You could have a batch file which runs osql with your complete script
HTH
Paul Ibison|||Or, read the script, line by line, and each time you encounter GO, execute what you have in the buffer.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:8781168A-8324-4DE5-ACDA-C975D4B21EEF@.microsoft.com...
> Sudhapec,
> from BOL: CREATE DEFAULT, CREATE PROCEDURE, CREATE RULE, CREATE TRIGGER, and CREATE VIEW statements cannot
be combined with other statements in a batch. Batches are delimited by the keyword GO in a script, hence your
problem. I guess you could create multiple scripts - one main one and a separate script for each of the above
commands. Another (easier) alternative would be to not use ADO.NET for this step, but OSQL. You could have a
batch file which runs osql with your complete script.
> HTH,
> Paul Ibison|||Below a link to a VB.Net code example that uses the technique Tibor
mentioned:
<http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=mK%252c
.2084%24Cm3.67%40newsread3.news.pas.earthlink.net&rnum=8&prev=/groups%3Fas_q
%3Dsqlcommand%2520go%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-8%26as_uauthors
%3DDan%2520Guzman%26lr%3D%26hl%3Den>
--
Hope this helps.
Dan Guzman
SQL Server MVP
"sudhapec" <sudhapec.153vii@.mail.webservertalk.com> wrote in message
news:sudhapec.153vii@.mail.webservertalk.com...
> Posted - 04/21/2004 : 09:26:34
> ----
--
> Friends
> I want to run sql script for creating of database which
> contains tables and stored procedures by setup and deployment project
> in VS.NET. I have created customaction and passing the string
> containing script to the ExecuteNonQuery() procedure to run the script
> The problem is where ever GO statement is there in the script it
> is giving problem. I read somewhere that
> " Your script must not include any go statements. These are used only
> by Query Analyzer or the osql.exe utility. If they are present in your
> script when using it with ADO.NET (as in this demo), then the
> ExecuteNonQuery will fail."
> If i remove Go from the script then it is giving exception again
> telling that "Incorrect syntax near the keyword Procedure"
> where ever create Procedure statement is there
> Please help me in this regard.
>
> --
> sudhapec
> ---
> Posted via http://www.webservertalk.com
> ---
> View this thread: http://www.webservertalk.com/message190433.html
>

No comments:

Post a Comment