B
Bonno Hylkema
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
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