Power sheel Script need to exicute Sql Server data project in Pre Post Build section.

Uma Mahesh U 1 Reputation point
2020-09-03T05:25:43.687+00:00

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?

Azure Database for PostgreSQL
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,564 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,546 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue 37,541 Reputation points Microsoft Vendor
    2020-09-03T08:21:10.513+00:00

    Hi,
    The error code 255 usually means that it is not able to find the file you are asking it to execute. Please make sure all the paths are correct. As it could be a MSBuild issue, you could add the tag "vs-msbuild".

    Best Regards,

    Ian

    Please remember to "Accept Answer" and upvote if the reply is helpful.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.