ZaphodBeeblebrox Creative Commons License 2007.07.23 0 0 252
Sziasztok!

Access+ODBC+MS SQL Server 2005

Van nekem egy ilyen eljárásoam ami a szerveren futtatna lekérdezésket:

Sub RunServerSQL (SQLstr As String)

Dim sqlWS As WorkSpace
Dim sqlDB As Database
Dim MyQuery As QueryDef

On Error GoTo RSS_H

Set sqlWS = DBEngine.Workspaces(0)
Set sqlDB = sqlWS.databases(0)

Set MyQuery = sqlDB.CreateQueryDef("")
MyQuery.connect = SQLConnectStrUzlet
MyQuery.returnsrecords = False

MyQuery.SQL = SQLstr

MyQuery.Execute

Set MyQuery = Nothing
'sqlDB.Close

'Set sqlDB = Nothing
'Set sqlWS = Nothing

Exit Sub
RSS_H:
MsgBox Err & ": " & Error$, 16, cv$
Exit Sub
End Sub


Az SQLStr a következő lenne:

USE [Uzlet]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ProbaTabla1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Megnevezes] [varchar](50) COLLATE Hungarian_CI_AS NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF

Amikor futtatom akkor ezt írja ki nekem:

3146: ODBC--a hívás nem sikerült. [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'GO'. (#102) [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'GO'. (#102) [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'G
O'. (#102) [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'GO'. (#102) [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near the keyword 'SET'. (#156)

Mi lehet a gondja?

ZB