Excel Sql Server QueryTable - SQL Server Error

querytable refreshes and returns data with select query by returns error with any of the update queries
Connection Failed
SQL State: '28000'
SQL Server Error: 18456

 Const sConnectDSN   As String = "ODBC;DSN=ABC"
Const sConnectUID   As String = "DEF"
Const sConnectPWD   As String = "ABC123"
Const sConnect      As String = sConnectDSN & ";UID=" & sConnectUID & ";PWD=" & sConnectPWD 

'upload query for update
Sub UploadSQL(sSQL As String)
    Dim objQT As Object
    Dim wsSQL As Worksheet
    Dim x     As Integer
    Set wsSQL = Worksheets(sSQLSHEET)
   ''' Delete all Existing Query Tables from previous execution
    If wsSQL.QueryTables.Count > 150 Then
        Application.DisplayAlerts = False
        Application.DisplayAlerts = True
        For x = 1 To wsSQL.QueryTables.Count
        Next x
    End If
    Set objQT = wsSQL.QueryTables.Add(Connection:=Array(Array(sConnect), Array("O=0;")), Destination:=Worksheets("sql").Cells(5, 1))
    objQT.Sql = sSQL
    Set objQT = Nothing
    Set wsSQL = Nothing
End Sub

'code used for a select query
    With ActiveSheet.QueryTables.Add(Connection:=sConnect, _
        Destination:=Range(sCol & "2"))
        .Sql = wsSetup.Cells(iRowSQL, iColClass).Value
        .FieldNames = False
        .RefreshStyle = xlInsertDeleteCells
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .RefreshOnFileOpen = False
        .HasAutoFormat = True
        .BackgroundQuery = False
        .TablesOnlyFromHTML = True
        .Refresh BackgroundQuery:=False
        .SavePassword = True
        .SaveData = True
        .Name = wsSetup.Cells(iRowRange, iColClass).Value
    End With


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
Why would you use a querytable, which is designed to display records, for an update query?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.