SqlClient 连接超时

发布于 2024-12-23 10:55:07 字数 533 浏览 5 评论 0原文

我正在编写一些 python 来与我有权访问的 MSSQL 服务器交互。我当前遇到的问题是我的交易语句之一没有超过默认设置的超时期限(30 秒)。

我尝试将连接字符串中的命令超时更改为 0,这样就不会出现问题,但我被告知不支持命令超时关键字。

这是我的连接字符串:

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

这是使用此连接字符串时收到的控制台消息:

Value Error: Keyword not supported: 'command timeout'

我尝试过带空格、不带空格以及带/不带大写字母的命令超时,具体取决于我当前在尝试时阅读的支持线程解决这个问题。

当更改连接字符串中的命令超时似乎不起作用时,这里有人知道将超时值设置为超过 30 秒的方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城旧梦 2024-12-30 10:55:07

或者,您可以执行以下操作:

import adodbapi 
adodbapi.connect(connectionString, 100)

第二个参数是超时。

Alternatively, you can do something like this:

import adodbapi 
adodbapi.connect(connectionString, 100)

The second parameter is the timeout.

舟遥客 2024-12-30 10:55:07

您可以在连接或命令对象本身上指定命令超时,而不是在连接字符串中指定。查看此资源以获取 ADO 连接对象。

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.

你的笑 2024-12-30 10:55:07

该站点列出了可以在连接字符串中设置的所有选项,但命令超时似乎并没有其中之一。

如果您在 Windows 上使用 Python 并使用 ADO,则可以在连接对象上设置命令超时:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文