title: read SQL and store value as variable on excel VBA.[ Run-time error '-2147467259 (80004005) ]
body: <p>i'm pretty new to sql and coding.<br> 
  <br>I want to read data from SQL and store it as variable on VBA to update cells in excel sheets, but when I run VBA, i encounter [Run-time error '-2147467259 (80004005)] from "rst.Open ssql, cn, adOpenDynamic, adLockPessimistic, adCmdText"<br><br> Please review my codes below. Thank you!</p>
  
  <p><a href="https://i.stack.imgur.com/fIWqF.png" rel="nofollow noreferrer">this is sql table</a></p>
  
  <pre><code>Sub sql_po_stackflow()
  
  Dim cn As ADODB.Connection
  Set cn = New ADODB.Connection
  Dim strConn As String
  
  strConn = "PROVIDER=SQLOLEDB;"
  strConn = strConn &amp; "DATA SOURCE=CINDY\MSSQLSERVER01;INITIAL CATALOG=mason01;"
  strConn = strConn &amp; "INTEGRATED SECURITY=sspi;"
  
  cn.Open strConn
  
  Dim r, c, endcol As Long
  Dim LastRow, LastColumn As Long
  Dim loc As Worksheet
  Set loc = ThisWorkbook.Sheets("Backend")
  
  With loc
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    LastColumn = .Range("A1").CurrentRegion.Columns.Count
  End With
  
  Dim rst As ADODB.Recordset
  Set rst = New ADODB.Recordset
  Dim ssql, gd, itn As String
  
  
      r = 161
      c = 14
      endcol = 21
  
      Do While (c &lt; endcol + 1)
          Do While (r &lt; LastRow + 1)
  
  
          itn = "XXX-XXX-XXX"
          ssql = "Select PONUMBER from po_east where ITEMNO = " &amp; itn &amp; ""
  
          rst.Open ssql, cn, adOpenDynamic, adLockPessimistic, adCmdText
  
          gd = rst!PONUMBER.Value
          rst.Close
  
          loc.Range(loc.Cells(r, c), loc.Cells(r, c)) = gd
  
          rst.Close
  
          r = r + 176
  
          Loop
  
      r = 161
      c = c + 1
  
      Loop
  
  cn.Close
  
  Set rst = Nothing
  Set cn = Nothing
  
  
  End Sub
  </code></pre>