Session和Connection有什么区别? [英] What is difference between Session and Connection?

查看:103
本文介绍了Session和Connection有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会话和连接有什么区别?任何人都可以用简单的方式解释它。我读了很多文章,但我没有得到它。我读的越多,我就越困惑。



提前致谢,

Pushkar

What is difference between Session and Connection? Could any one explain it in simple way. I read many articles but I didn't get it. The more I read, the more I am getting confused.

Thanks in advance,
Pushkar

推荐答案

让我们退一步,暂时忽略电脑。



你想开车去商店。

要做到这一点,你需要做两件事:

1)上车。

2)用你的驾驶技巧导航你的方式。 />
这些是单独的事件 - 除非你在车里,否则没有必要尝试导航! 进入汽车建立了你是汽车之间的联系,虽然存在这种联系,但你可以进行一次导航。如果您在任何时候下车,您已经断开连接,导航会话结束。



从SQL的角度来看,它是相同的,您的应用程序建立与SQL Server的连接 - 它们之间的物理链接 - 并且SQL Server建立一个Session,您可以在其中通过连接发出命令。如果在任何时候关闭连接,则会话结束 - 例如,如果您使用事务处理,那么它们将在此时自动回滚,因为您没有提交它们。



实际上,它比那更复杂 - 每个连接可以有多个会话(但不是相反,两个连接不能共享一个会话)在某些情况下,在某些情况下,你可以在没有连接的情况下进行会话。



但在实践中(以及99.99%的工作年限)您可以将两者视为相同:连接建立会话,并且会话在连接终止时结束。
Let's take a step back, and ignore computers for a moment.

You want to drive to the shops.
To do this, you need to do two things:
1) Get into the car.
2) Use your driving skills to navigate your way.
These are separate "events" - there is no point in trying to navigate unless you are in the car! "Getting into the car" establishes a connection between you are the car, and while that connection exists, you can have a session of navigation. If at any point you get out of the car, you have broken the connection, and the navigation session ends.

From an SQL perspective, it's the same, your application establishes a connection to SQL Server - the "physical" link between them - and SQL Server establishes a Session within which you can issue commands over the connection. If at any time the connection is closed, your session ends - and if you are using Transactions for example, they will automatically be "rolled back" at that point because you didn't Commit them.

In reality, it's more complex than that - you can have more than one session per connection (but not the other way round, two connections cannot "share" a session) under some circumstances, and there are some conditions under which you can have a session without a connection.

But in practice (and for 99.99% of your working life) you can treat the two as the same: a connection establishes a session and the session ends when the connection is terminated.


这篇关于Session和Connection有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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