We help IT Professionals succeed at work.
Get Started

Powershell Sql query Timing out

769 Views
Last Modified: 2015-03-31
Code below work fine. But there arew times it falls into issues. The issues is with the timeout value. Is there a way have it not time out. There are times the query can take 2 or 3 minutes and theirs no issue.Sometimes query can take 3 to 6 hours and it works its just that theres a lot of records to process in SQL Studio the query works fine no timeout. When it starts to take that long when executed from Powershell it timesout.

My question is how to I code this so it does not time out. I put in a parameter but it a time value for time out can I have it where it wont time out and let the query run its course.


add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue
add-pssnapin sqlservercmdletsnapin100 -ErrorAction SilentlyContinue


$Servers = Get-Content "C:\NOCScripts\SQL\AuditPending\AuditPendingLog.txt"

Foreach($server in $Servers){

invoke-sqlcmd -inputfile "C:\NOCScripts\SQL\AuditPending\AuditRecords.sql" -serverinstance $server -database "master" -QueryTimeout 20000 

}

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE