Re: Run SQL comand with String from SQL Script (Added...)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



GO is not a TRANSACT SQL keyword

It is a batch separator used by Query Analyzer (and its siblings).

Split your script on the GO keyword and execute each segment by itself.

"MATT" <MATT@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E25AB483-02BA-4818-BA09-99120A64A34C@xxxxxxxxxxxxxxxx
In the SQL Script, after each EXEC line, it is followed by a 'GO' command.
When i remove the go, it seems to work much better. Can Anyone explain?

"MATT" wrote:

Using SQL 2005 I generated a SQL Script to create a DB Table and columns.
in
VB.NET i use the StreamReader to read this file to a string, and I want
to
execute the script in my application, so the app can create an identical
table at runtime.

Obvously if i simply run the SQL Script from the file, it works, and if I
copy the StreamReader String while debugging into a SQL query, it also
works
(creates the table) fine. However, when the program steps to the
SqlCmd.ExecuteNonQuery( ), I get a SQL Exception, "Syntax error
near....".
The sql script (and command string) are very long, (Many tables, many
properties... many "Syntax error near"). I've tried to Replace single
(apostrophe) ' with '' and even single (quote) " with "", but the same
result. How come if I paste the string directly from the app to the
query
analizer it works, but errors out in the app? Any suggestions?

Thanks
MATT


.



Relevant Pages

  • Re: Problems with Delete Command
    ... The SQL could get fairly messy if you need to construct it in code, ... ContactID, and WebComID, and create your on-the-fly SQL on that saved query, ... to find the list of ContactIDs from the junction table, ... This is a style/readability thing: if you are going to use string ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Need help with Code Please!!!
    ... posted in response to my last post was some SQL, but this is not the SQL that ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)
  • Re: Query to Filter by Dates, Using Form
    ... This is the SQL that works: ... Dim strDateCondition As String ... drop the stored query and create a new one with the SQL you have built? ...
    (microsoft.public.access.queries)
  • RE: Upgrade DTS to SSIS using script
    ... you would execute against the AS400 Connection Manager. ... Put in a Script Task above the Data Flow and specify SQLCommand in the ... Dim sql as string ...
    (microsoft.public.sqlserver.dts)
  • Re: Requery subform
    ... are just changing the SQL? ... remove this function and relevent code because the query always exists. ... Dim strProjectType As String ... Dim strProjectStatus As String ...
    (comp.databases.ms-access)