H
H
HighMan2021-01-31 01:27:40
PowerShell
HighMan, 2021-01-31 01:27:40

MS SQL why did the query time out?

Hello comrades!
I took care of writing a Power Shell script to backup several databases from MS SQL.

$Server = "localhost"
$BaseName = "master"
$BaseLogin = "user"
$BasePassw = "password"
$connection = New-Object -com "ADODB.Connection"
$ConnectionString = "Provider=SQLOLEDB.1;
                     Data Source=$Server;
                     Initial Catalog=$BaseName;
                     User ID=$BaseLogin;
                     Password=$BasePassw;
         Connection Timeout=0;"
$connection.Open($ConnectionString)
$connection.Execute("BACKUP DATABASE [db_name] TO DISK = 'd:\bak\db_name.sql' WITH INIT, NOFORMAT, SKIP, NOUNLOAD")
$connection.Close()

This is, of course, stripped-down code and returns an error: Exception calling "Execute" with "1" arguments: "Request timed out".
At the same time, if you run a query from Management Studio, then the query is executed without errors. The execution time is just over 2 minutes.
After digging around the Internet, I found advice to play around with the Connection Timeout in the connection string. They promise that with a value of "0" the timeout error should disappear. It was not there ...
Tell me, plz, how to overcome this trouble?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HighMan, 2021-01-31
@HighMan

Ugh, infection!
Lost so much time ... The
Connection Timeout=600;
zero value of the timeout, apparently, tightens the default value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question