locked
How to Add Power Shell Script in Sql Server Data project pre Build event to Connect Postgres Sql. RRS feed

  • Question

  • Hi Team,

    i am trying to connect postgres ODBC driver into SQL server data project to compare the Schema.

    Power Shell script is:

    ion Get-ODBC-Data{

       param([string]$query=$(throw 'query is required.'))    $conn = New-Object System.Data.Odbc.OdbcConnection    $conn.ConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=localhost;Port=5432;Database=nyc_data;Uid=postgres;Pwd=postgres;"    $conn.open()    $cmd = New-object System.Data.Odbc.OdbcCommand($query,$conn)    $ds = New-Object system.Data.DataSet    (New-Object system.Data.odbc.odbcDataAdapter($cmd)).fill($ds) | out-null    $conn.close()    $ds.Tables[0] } function Set-ODBC-Data{    param([string]$query=$(throw 'query is required.'))   $conn = New-Object System.Data.Odbc.OdbcConnection   $conn.ConnectionString= "Driver={PostgreSQL Unicode(x64)};Server=localhost;Port=5432;Database=nyc_data;Uid=postgres;Pwd=postgres;"   $cmd = new-object System.Data.Odbc.OdbcCommand($query,$conn)   $conn.open()   $cmd.ExecuteNonQuery()   $conn.close() } $query = "select * from ***" $result = Get-ODBC-Data -query $query set-odbc-data -query $query

    in Power shell script it's successfully connected and same code moved to pre build event in sql server data base project.

    getting the below error and please help me on this?

    Severity

    Code

    Description

    Project

    File

    Line

    Suppression State

    Error

    03073: The command "function Get-ODBC-Data{   param([string]$query=)   $conn = New-Object System.Data.Odbc.OdbcConnection   $conn.ConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=localhost;Port=5432;Database=nyc_data;Uid=postgres;Pwd=postgres;"   $conn.open()   $cmd = New-object System.Data.Odbc.OdbcCommand($query,$conn)   $ds = New-Object system.Data.DataSet   (New-Object system.Data.odbc.odbcDataAdapter($cmd)).fill($ds) | out-null   $conn.close()   $ds.Tables[0]}function Set-ODBC-Data{   param([string]$query=)  $conn = New-Object System.Data.Odbc.OdbcConnection  $conn.ConnectionString= "Driver={PostgreSQL Unicode(x64)};Server=localhost;Port=5432;Database=nyc_data;Uid=postgres;Pwd=postgres;"  $cmd = new-object System.Data.Odbc.OdbcCommand($query,$conn)  $conn.open()  $cmd.ExecuteNonQuery()  $conn.close()}$query = "select * from ***"$result = Get-ODBC-Data -query $queryset-odbc-data -query $query" exited with code 255.

    Database1

    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets

    1330

    is there any option to connect as a postgres sql as source in database connection in sql server data project?


    Wednesday, September 2, 2020 5:25 PM

All replies

  • Hi Postgres2049,
    For questions about powershell, it is recommended to ask the questions in Microsoft Q&A forum and you can get more professional answer.
    Thank you for your understanding.
    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Thursday, September 3, 2020 1:37 AM