SQLDMO.ExecuteWithResultsAndMessages2 Method

  • I Used SQLServer 2000/2005 with VB 6.0. I used SQLDMO in My Application.

    I try to Execute a batch script with SQLServer2.ExecuteWithResultsAndMessages2 method. but every time i got error message "incorrect syntax near 'GO'"

    Full Code is:

    Dim sSqlServer As New SQLDMO.SQLServer2

    Dim sDatabase As SQLDMO.Database2

    Dim qResult As SQLDMO.QueryResults2

    Dim sMsg As String

    Dim sCommand As String

    Call sSqlServer.Connect("Server", "UID", "PWD")

    Set sDatabase = sSqlServer.Databases("MyDB")

    sCommand = "/*MyScript.SQL*/" & vbCrLf

    sCommand = sCommand & "SET NOCOUNT ON" & vbCrLf

    sCommand = sCommand & "SELECT * FROM MyTable" & vbCrLf

    sCommand = sCommand & "Print Cast(@@RowCount As VarChar) + ' Record(s) Found'" & vbCrLf

    sCommand = sCommand & "SET NOCOUNT OFF" & vbCrLf

    sCommand = sCommand & " GO"

    Set qResult = sDatabase.ExecuteWithResultsAndMessages2(sCommand, sMsg, Len(sCommand))

    Msgbox sMsg

    Msgbox qResult.Rows

    Pls any one solve my problem.

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply