尽管在Conn String中有300秒的超时
我正在开设与SQL Azure无服务器数据库的连接。 该数据库如果未使用1小时就会暂停。
我通过Azure函数连接到此数据库。 conn.open();尽管连接字符串将超时设置为300秒,但在10秒后排出了线。 该数据库也不在此连接尝试中毫无疑问。
我以为当建立连接时会重新启动,这可能需要几分钟,但是代码似乎忽略了连接字符串超时值。
我应该设置此超时的其他地方吗?
conn字符串:
Server=tcp:myDBServer.database.windows.net,1433;Initial Catalog=sample-Db;Persist Security Info=False;User ID={your_user};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;
I am opening a connection to a sql azure serverless database.
This database pauses if unused for 1 hour.
I connect to this database via an azure function. The conn.open(); line times out after 10 seconds despite the connection string having timeout set to 300 seconds.
The database is also not unpausing on this connection attempt.
I had assumed that when a connection is made it will restart, and this may take a few minutes but the code seems to be ignoring the connection string timeout value.
Is there somewhere else i should set this timeout?
Conn String:
Server=tcp:myDBServer.database.windows.net,1433;Initial Catalog=sample-Db;Persist Security Info=False;User ID={your_user};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
超过 30分钟空闲连接可以通过Azure SQL数据库关闭。
如果您从 ssms 或任何其他应用程序 持续时间长于 30 分钟,而无需任何主动请求,则您的会话将超时。
默认
idletimeout
在关闭未使用连接之前的参数为300000
ms,足以容纳Azure SQL连接。请检查该线程中给出的解决方法:
在执行C#Azure函数时如何避免SQLClclient超时错误?
More than 30 minutes idle connections can be closed by Azure SQL Database.
If you're connected from SSMS or any other applications to the Azure SQL DB for longer than 30 minutes without any active request, your session will timeout.
The default
idleTimeout
parameter before closing an unused connection is300000
ms which would be enough for Azure SQL Connections.Please check the workarounds given in this thread:
How can I avoid a SqlClient timeout error during execution of a C# Azure Function?
连接串中的连接超时仅控制连接的超时。如果您需要增加命令上的等待时间,请使用
commandtimeout
sqlCommand
的属性。The Connection Timeout in the ConnectionString only controls the timeout for the connection. If you need to increase the wait time on your Commands, use the
CommandTimeout
property ofSqlCommand
.