我应该怎么做?我使用公共共享时出错。 [英] How should I do? I have error when I use public shared.

查看:76
本文介绍了我应该怎么做?我使用公共共享时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用公共共享来创建函数连接数据库。



现在我有问题当用户使用同一时间,数据混淆或错误无效操作。连接已关闭。





请告知我该怎么办?

I use "public shared" for created function connect database.

now i have problem when user use same time ,data are confuse or error " Invalid operation. The connection is closed."


Please advise How should I do?

推荐答案

没有看到相关的代码部分,它或多或少像猜测。



但是根据你收到的消息:无效的操作。尝试操作数据库时关闭连接。例如,在执行SqlCommand之前,您尚未打开(或已关闭)连接。



根据堆栈信息,找到问题发生的位置并确保您在需要时打开连接。



一种简单的方法是每次操作数据库时打开连接,然后在操作后关闭它。这样每次都重新打开连接。如果配置正确,连接池将通过缓存已关闭的连接以供以后使用来确保正确的连接时间。
Without seeing relevant code parts it's more or less like guessing.

But based on the message you receive: Invalid operation. The connection is closed when you try to operate the database. For example you haven't opened (or have closed) the connection before executing a SqlCommand.

Based on the stack information, locate where the problem occurs and ensure that you have the connection open when needed.

One simple way is that you open the connection each time you operate the database and then close it after the operation. This way the connection is re-opened every time. The connection pooling, when configured properly, will ensure proper connection times by caching the closed connections for later use.


public shared表示所有用户都调用相同的功能,因此它可能是一个请求正在关闭连接,而另一个请求仍在使用它,特别是如果连接对象本身是共享的。避免对必须特定于每个请求的事物使用共享。
"public shared" means all users call the same function, so it could be that one request is closing the connection while another request is still using it, especially if the connection object itself is shared. Avoid using "shared" for things that have to be specific to each request.


这篇关于我应该怎么做?我使用公共共享时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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