在Classic asp中,我可以在Session对象中存储数据库连接吗?

时间:2021-08-12 01:32:49

Can I store a database connection in the Session object?

我可以在Session对象中存储数据库连接吗?

5 个解决方案

#1


5  

It is generally not recommended to do so, a connection string in the Application variable, with a nice helper function/class is a much preferred method. Here is some reference. (Dead link removed because it now leads to a phishy site)

通常不建议这样做,Application变量中的连接字符串,带有一个好的辅助函数/类是一个非常优选的方法。这里有一些参考。 (删除了死链接,因为它现在导致了一个网站)

#2


2  

I seem to recall doing so will have the effect of single threading your application which would be a bad thing.

我似乎记得这样做会产生单线程应用程序的效果,这将是一件坏事。

#3


2  

In general, I wouldn't store any objects in Application variables (and certainly not in session variables).

通常,我不会在Application变量中存储任何对象(当然也不会存储在会话变量中)。

When it comes to database connections, it's a definite no-no; besides, there is absolutely no need.

谈到数据库连接,这是一个明确的禁忌;此外,绝对没有必要。

If you are use ADO to communicate with the database, if you use the same connection string (yes, by all means, store this in an Application variable) for all your database connections, 'connection pooling' will be implemented behind the scenes. This means that when you release a connection, it isn't actually destroyed - it is put to one side for the next guys who wants the same connection. So next time you request the same connection, it is pulled 'off the shelf' rather than having to be explicitly created and instantiated - which is a quite a nice efficiency improvement.

如果使用ADO与数据库进行通信,如果对所有数据库连接使用相同的连接字符串(是的,将其存储在Application变量中),则会在后台实现“连接池”。这意味着当你释放一个连接时,它实际上并没有被破坏 - 它被放在一边,为下一个想要相同连接的人。因此,下次您请求相同的连接时,它将被“提供”,而不是必须明确创建和实例化 - 这是一个非常好的效率改进。

#4


1  

From this link http://support.microsoft.com/default.aspx/kb/243543

从此链接http://support.microsoft.com/default.aspx/kb/243543

You shouldnt store database connection in Session.

您不应该在Session中存储数据库连接。

From what I understand, if you do then subsequent ASP requests for the same user must use the same thread.

根据我的理解,如果你这样做,那么对同一用户的后续ASP请求必须使用相同的线程。

Therefore if you have a busy site its likely that 'your' thread will already be being used by someone else, so you will have to wait for it to become available.

因此,如果您有一个繁忙的站点,那么“您的”线程可能已被其他人使用,因此您必须等待它变得可用。

Multiply this up by lots more users and you will get everyone waiting for everyone elses thread and a not very responsive site.

乘以更多用户,你会得到每个人等待所有人的线程和不太敏感的网站。

#5


-2  

As said by CJM, there is no need to store a connection in a Session object : connection pooling is much better.

正如CJM所说,不需要在Session对象中存储连接:连接池更好。

#1


5  

It is generally not recommended to do so, a connection string in the Application variable, with a nice helper function/class is a much preferred method. Here is some reference. (Dead link removed because it now leads to a phishy site)

通常不建议这样做,Application变量中的连接字符串,带有一个好的辅助函数/类是一个非常优选的方法。这里有一些参考。 (删除了死链接,因为它现在导致了一个网站)

#2


2  

I seem to recall doing so will have the effect of single threading your application which would be a bad thing.

我似乎记得这样做会产生单线程应用程序的效果,这将是一件坏事。

#3


2  

In general, I wouldn't store any objects in Application variables (and certainly not in session variables).

通常,我不会在Application变量中存储任何对象(当然也不会存储在会话变量中)。

When it comes to database connections, it's a definite no-no; besides, there is absolutely no need.

谈到数据库连接,这是一个明确的禁忌;此外,绝对没有必要。

If you are use ADO to communicate with the database, if you use the same connection string (yes, by all means, store this in an Application variable) for all your database connections, 'connection pooling' will be implemented behind the scenes. This means that when you release a connection, it isn't actually destroyed - it is put to one side for the next guys who wants the same connection. So next time you request the same connection, it is pulled 'off the shelf' rather than having to be explicitly created and instantiated - which is a quite a nice efficiency improvement.

如果使用ADO与数据库进行通信,如果对所有数据库连接使用相同的连接字符串(是的,将其存储在Application变量中),则会在后台实现“连接池”。这意味着当你释放一个连接时,它实际上并没有被破坏 - 它被放在一边,为下一个想要相同连接的人。因此,下次您请求相同的连接时,它将被“提供”,而不是必须明确创建和实例化 - 这是一个非常好的效率改进。

#4


1  

From this link http://support.microsoft.com/default.aspx/kb/243543

从此链接http://support.microsoft.com/default.aspx/kb/243543

You shouldnt store database connection in Session.

您不应该在Session中存储数据库连接。

From what I understand, if you do then subsequent ASP requests for the same user must use the same thread.

根据我的理解,如果你这样做,那么对同一用户的后续ASP请求必须使用相同的线程。

Therefore if you have a busy site its likely that 'your' thread will already be being used by someone else, so you will have to wait for it to become available.

因此,如果您有一个繁忙的站点,那么“您的”线程可能已被其他人使用,因此您必须等待它变得可用。

Multiply this up by lots more users and you will get everyone waiting for everyone elses thread and a not very responsive site.

乘以更多用户,你会得到每个人等待所有人的线程和不太敏感的网站。

#5


-2  

As said by CJM, there is no need to store a connection in a Session object : connection pooling is much better.

正如CJM所说,不需要在Session对象中存储连接:连接池更好。