Re: Running T_SQL script from Access (I can't get it right)
- From: "Bonno Hylkema" <bonno.hylkema@xxxxxxxxx>
- Date: Fri, 1 Sep 2006 13:20:09 +0200
I was not familiar with the difference, but after some reading I now do
understand. GO is for Query Analyzer.
When you generate a SQL script from Enterprise Manager it will have multiple
GO's for each step in the script. Since I like to use the generated script
without manual updating, I came across an interesting post by Tibor Karaszi:
"Loop through the stuff that you want to execute, insert each row into a
variable until
you reach GO. Execute that variable. Continue looping. Don't send the GO."
This approach looks pretty good to me and I will try it out using VBA in
Access.
Do you have an idea about my second question: How should fs, f and ts be
DIMmed?
Many thanks for your reply.
Bonno Hylkema
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
schreef in bericht news:Oqn0jtRzGHA.3908@xxxxxxxxxxxxxxxxxxxxxxx
Remove the GO, this is a batch command, not a T-SQL command.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Bonno Hylkema" <bonno.hylkema@xxxxxxxxx> wrote in message
news:44f705c3$0$2019$ba620dc5@xxxxxxxxxxxxxxxxxxxxxx
It might be an old subject, Running T_SQL script froms Access, but I
can't get it right.
I am running Access 2003 and SQL Server 2000.
I generate a SQL script from Enterprise Manager through Generate SQL
script, options International Text (Unicode).
The script Table1.sql looks like follows:
CREATE TABLE [dbo].[Table1] (
[Field1] [int] NOT NULL ,
[Field2] [char] (50) COLLATE Latin1_General_CI_AS NULL ,
[Field3] [char] (50) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO
In the Access adp I have a function that should read the contents of the
Table1.sql script file and execute the T_SQL command on SQL Server. The
function has the following code:
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs
Dim f
Dim ts
Dim SQL As String
Dim cnn As ADODB.Connection
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("C:\Temp\Table1.SQL")
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
SQL = ts.ReadAll
MsgBox SQL
ts.Close
Set cnn = CurrentProject.Connection
cnn.Execute SQL, , adCmdText
cnn.Close
When I run the code I get the error: Line 6: Incorrect syntax near 'GO'.
What is wrong with my setup? The MsgBox shows the proper commands, as far
as I can tell.
How should fs, f and ts be DIMmed?
Any help is welcome. Thanks in advance.
Bonno Hylkema
.
- Follow-Ups:
- Re: Running T_SQL script from Access (I can't get it right)
- From: Douglas J. Steele
- Re: Running T_SQL script from Access (I can't get it right)
- Prev by Date: Re: Audit logging an adp
- Next by Date: Re: Running T_SQL script from Access (I can't get it right)
- Previous by thread: Re: Running T_SQL script from Access (I can't get it right)
- Next by thread: Re: Running T_SQL script from Access (I can't get it right)
- Index(es):
Relevant Pages
|