我可以避免使用本地数据库关闭SqlConnection吗? [英] Can I avoid closing a SqlConnection with a local db?

查看:99
本文介绍了我可以避免使用本地数据库关闭SqlConnection吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在编写一个使用连接到mdf sql db的应用程序。

我使用的是SqlConnection对象。

由于db是本地的,除了我之外没有人可以访问,我可以保持从应用程序开始到结束的连接打开吗?



非常感谢!



Jymmy097

解决方案

你可以像Wes一样说。但是......这不是一个好主意。

如果你只是在本地使用它,那么你可能不应该通过SQL使用它 - ACE / ODBC可能是一个更好的主意,因为这意味着您 更改代码以将其转换为多用户系统。将SQL用于单个用户并为单个用户编码是危险的,因为在3个月的时间内,您将忘记当您将软件发布给其他十几个用户并骄傲地看着整个系统不时出现时。 ..:笑:



这是一个糟糕的做法有一个原因:因为它们可能会在以后出现问题很多时,找到并修复它们会更加昂贵。 / BLOCKQUOTE>

Hi,

I'm writing an application which uses a connection to a mdf sql db.
I use this using a SqlConnection object.
Since the db is a local one which no-one can access but me, can I keep the connection opened from the application starting to the ending?

Thanks a lot!

Jymmy097

解决方案

You can, as Wes has said. But... It isn't a good idea.
If you are using it locally only, then probably you shouldn't be using it via SQL - ACE/ODBC is probably a better idea, because it means that you have to change the code in order to convert it to a multiuser system. Using SQL for single user and coding for a single user is dangerous, because in 3 months time you will have forgotten that when you release the software to a dozen other users and sit back in pride watching the whole system fall over from time to time... :laugh:

It's poor practice for a reason: because they can cause problems later on when it's a lot, lot more expensive to find and fix them.


这篇关于我可以避免使用本地数据库关闭SqlConnection吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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