Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Executing Stored Procedure Script from VB.Net

Author  Topic 

prakashdotc
Starting Member

25 Posts

Posted - 2006-09-21 : 08:29:42
Hi All,

I'm generating a Script of stored procedures from a database as 'DatabaseNameSP.sql'. Is it possible to run this script from VB.Net.....i tried to execute this script by forming the content of script file as a string and passing it SqlCommand object with ExecuteNonQuery() - but this throws error at "GO" and "CREATE PROCEDURE' must be the first statement in a query batch" etc. is there any other go for this problem. thank's in advance

- Prakash.C

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 08:59:31
Why not store the procedure in the database and call the SP from vb.net?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-09-21 : 09:16:53
quote:
Originally posted by prakashdotc

Hi All,

I'm generating a Script of stored procedures from a database as 'DatabaseNameSP.sql'. Is it possible to run this script from VB.Net.....i tried to execute this script by forming the content of script file as a string and passing it SqlCommand object with ExecuteNonQuery() - but this throws error at "GO" and "CREATE PROCEDURE' must be the first statement in a query batch" etc. is there any other go for this problem. thank's in advance

- Prakash.C



GO is not a valid T-SQL keyword, it is just used to Query Analyzer to seperate a single .sql file into multiple batches.

If you wish to read in a .sql file with "GO" in it and execute it, you'll need to split it up into multiple commands (delimited by GO's) and execute each segment one at a time.


- Jeff
Go to Top of Page

prakashdotc
Starting Member

25 Posts

Posted - 2006-09-21 : 10:07:22
Hi Jeff,

thank u for U'r reply, as u said we can split the content with 'GO' but the script includes statements like

"SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO"

how to handle these case...?

- Prakash.C
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-09-21 : 10:13:33
quote:
Originally posted by prakashdotc

Hi Jeff,

thank u for U'r reply, as u said we can split the content with 'GO' but the script includes statements like

"SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO"

how to handle these case...?

- Prakash.C



the exact same way .. those are just T-SQL commands ....

- Jeff
Go to Top of Page

prakashdotc
Starting Member

25 Posts

Posted - 2006-09-22 : 07:41:42
Hi Jeff, thank U for U'r reply as u said i delimited the file with 'GO', splited each and every statement seperately and executed seperately, it's working file. thank u
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-09-22 : 08:16:36
You're welcome! Glad it worked for you.

- Jeff
Go to Top of Page
   

- Advertisement -