Question

I am writing some python to interact with a MSSQL server that I have access to. The issue I am currently having is that one of my transact statements is not getting past the timeout period that is set by default (30 seconds).

I have tried to change the Command Timeout in the connections string to have a value of 0 so that this will not be an issue, but am being told that the Command Timeout keyword is not supported.

Here is my Connection String:

conn_string='data source=localhost;initial_catalog=research;trusted_connection=True;Connection Timeout=0;Command Timeout=0'

Here is the console message I get when using this connection string:

Value Error: Keyword not supported: 'command timeout'

I have tried command timeout with the space, without the space, and with/without capital letters depending on whichever support thread I was currently reading while trying to resolve this issue.

Does anyone here know of a way to set the timeout value to be longer than 30 seconds when changing the Command Timeout in the connection string does not seem to be working?

Was it helpful?

Solution

You specify a command timeout on the connection or command object itself, not in the connection string. Check out this resource for ADO connection objects.

OTHER TIPS

Alternatively, you can do something like this:

import adodbapi 
adodbapi.connect(connectionString, 100)

The second parameter is the timeout.

This site lists all options you can set in a connection string, but command timeout does not appear to be one of them.

If you're using Python on Windows and are using ADO, you can set the command timeout on the connection object:

conn = Dispatch('ADODB.Connection')
conn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=localhost;" + \
  "uid=my_user_name;pwd=my_password;database=my_database_name"
conn.Open()
conn.CommandTimeout = 60
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top