Forum Discussion

Ganesh955's avatar
Ganesh955
Copper Contributor
Aug 06, 2023

PnP power shell script code to connect the SQL database and get the data into dataset

PnP code to connect the SQL database and get the data into dataset by using select query

2 Replies

  • Hi!

    I don't think you really understand what PnP is? It hasn't anything to do with SQL or SQL Databases, neither does SharePoint Online.

    It's better if you give us an explanation on what you want to do so we can help you
    • Ganesh955's avatar
      Ganesh955
      Copper Contributor

      I am getting the data into the data-reader after connecting and getting the data from SQL database table. Instead-of this I want to load the data into the data table or dataset so that I can close the SQL connection ($connection.Close()) to improve the performance.


      My present code for your reference below :-

      $command = New-Object System.Data.SqlClient.SqlCommand($query, $connection)
      $reader = $command.ExecuteReader()

      while ($reader.Read())
      {
      for ($i = 0; $i -lt $Reader.FieldCount; $i++)
      {

      $SourceSiteUrl = $Reader.GetValue(0)
      $TargetSiteUrl =$Reader.GetValue(1)

      }

      }

      }
      catch
      {
      Write-Host "Update exception msg " $_.Exception.Message
      }
      finally
      {
      $connection.Close()
      }

Resources