1

Need help with my Powershell. I am getting error

Exception calling "ExecuteReader" with "0" argument(s): "ERROR [57014] ERROR: canceling statement due to statement timeout; Error while executing the query" At line:1 char:1

My PowerShell as below:

$datetime = (Get-Date).ToString(); 
$sw = [Diagnostics.Stopwatch]::StartNew() 
$DBConnectionString ="Dsn=PostgreSQL;database=test;server=10.x.x.xx;port=5432;uid=xxx;pwd=xxx" 
$DBConn = New-Object System.Data.Odbc.OdbcConnection; $DBConn.ConnectionString = $DBConnectionString; 
$DBConn.Open(); 
$DBCmd = $DBConn.CreateCommand(); 
$DBCmd.CommandText= get-content "C:\data1.sql" 
$rdr=$DBCmd.ExecuteReader(); 
$instance = "DB\DBTEST" 
$userId = "sa" 
$password = "xxxx" 
$sqlconn = "Data Source=$instance;Integrated Security=SSPI;Initial Catalog=Conversion; User Id=$userId; Password=$password"; 
$sqlbc = new-object system.data.sqlclient.Sqlbulkcopy($sqlconn); 
$sqlbc.BulkCopyTimeout = 0; 
$sqlbc.DestinationTableName="Table"; 
$sqlbc.WriteToServer($rdr); 
$sw.Stop(); 
Write-Host "[$($datetime)] [data1] Elapsed time $($sw.Elapsed.TotalMilliseconds) miliseconds"

Really appreciate your help

2
  • 1
    Dsn=PostgreSQL I removed the incorrect SQL Server tag. Commented Aug 8, 2021 at 9:40
  • 1
    As per the error you received, how long is this running for before it errors? Have you looked into the CommandTimeout property of the connection? Commented Aug 8, 2021 at 9:44

2 Answers 2

1

Database timeouts means database network accessibility (e.q. firewalls) or DB down issues most of the time. First of all try to check TCP connectivity to DB:

New-Object System.Net.Sockets.TcpClient('10.x.x.xx', 5432)

If it throws errors you or your admins have to open access to DB port to your workstation first.

Sign up to request clarification or add additional context in comments.

2 Comments

I have ping and telnet, its successful. but still getting that error
Can you access DB from other Postgres clients like pgAdmin from your workstation?
0

For me, I was getting this timeout error because my client was sending too much data and the execution would timeout.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.