如果连接丢失,如何自动重新连接sql连接 [英] how to reconnect sql connection automatical if connection loss

查看:127
本文介绍了如果连接丢失,如何自动重新连接sql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#win表单项目中有一个sql连接



i如果连接丢失就想重新连接这个..

怎么办这个



谢谢

I have a sql connection in c# win form project

i want to reconnect this if connection is drop..
how to do this

thanks

推荐答案

你应该调查的第一件事是连接丢失的原因。如果这是一个可接受且常见的情况,那么我建议使用连接池,以便在每个工作单元之后,程序关闭连接,并在新工作单元开始的地方重新打开。



有关详细信息,请参阅 SQL服务器连接池(ADO.NET) [ ^ ]。



另请注意 ConnectRetryCount ConnectRetryInterval in ConnectionString [ ^ ]
The first thing you should investigate is why the connection is lost. If this is an acceptable and 'common' situation then I'd suggest using connection pooling so that after each unit of work the connection is closed by your program and re-opened where a new unit of work is started.

For more information, see SQL Server Connection Pooling (ADO.NET)[^].

Also notice both ConnectRetryCount and ConnectRetryInterval in ConnectionString[^]


请尝试以下操作..



1)自动重新连接MS Sever SQL连接

2)安全保持数据库连接长时间打开
Try the following..

1) Automatic reconnect MS Sever SQL connection
2) is it safe to keep database connections open for long time


这篇关于如果连接丢失,如何自动重新连接sql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆