讨论一个数据库连接的问题!!

时间:2022-12-11 18:59:52
以前用PB写对数据库的操作时,都是在程序打开以后就持续的连上数据库,直到关掉程序。这样数据库的同时连接数很大,现在一般在500左右,而且经常性的发生阻塞。
昨天在看C#,C#在进行数据库操作时,都是在有数据请求时使用OPEN()打开连接,操作完成了再CLOSE(),就在想:PB的操作是不是也能这么做?在有数据操作时才打开连接,操作完成就关闭?不过这样资源释放了,效率会不会下降?
大家有这么试过的吗?可以来发表一下自己的意见啊~~~

14 个解决方案

#1


pb也可以
不用的时候可以用disconnect来断开,与.net的close一样的.

#2


当然可以使用Disconnect断开,不过释放资源时效率肯定会差些,不过有得必有失,这是正常的。

#3


disconnect

#4


主要是这么操作带来的效率低下,哪个更符合应用的要求呢?
毕竟大部分时候在操作数据库,每次连接要花费不少的时间啊。。。

#5


可否把两种方案中合一下,比如在打开应用程序时"connect"改为在打开特定窗口时'connect';如果数据量较小;直接把数据取到前台操作;后断开数据库等等

#6


可以  在设置事务对象时用  setTrans (sqlca), 不用 setTransObject (sqlca)

setTransObject (sqlca)是一直连接

setTrans (sqlca)在执行的时候自动在连接,执行完毕后自动释放资源,适合连接数目大的系统

#7


SetTransObject versus SetTrans  In most cases, use the SetTransObject method to specify the transaction object because it is efficient and gives you control over when transactions are committed.

The SetTrans method provides another way of managing the database connection. SetTrans, which sets transaction information in the internal transaction object for the DataWindow control or DataStore, manages the connection automatically. You do not explicitly connect to the database; the DataWindow connects and disconnects for each database transaction, which is less efficient but necessary in some situations.

#8


可以  在设置事务对象时用  setTrans (sqlca), 不用 setTransObject (sqlca)

setTransObject (sqlca)是一直连接

setTrans (sqlca)在执行的时候自动在连接,执行完毕后自动释放资源,适合连接数目大的系统

对,如果真要这么做我建议用这种方法

#9


把PB的帮助拿出来翻了一下
You must use SetTransObject with DataWindow objects that use the Composite presentation style. Composite DataWindows are containers for other DataWindow objects and do not have any internal transaction information of their own.

If you use SetTrans with each nested DataWindow in a composite DataWindow, disconnect does not occur until the PowerBuilder session ends. 
Use SetTrans when you want PowerBuilder to manage the database connections automatically because you have a limited number of available connections or will be using the application from a remote location. SetTrans is appropriate when you are only retrieving data and do not need to hold database locks on records the user is modifying. However, for better performance, you should use SetTransObject.

When you use SetTrans to specify the transaction object, you cannot update multiple DataWindow objects or multiple tables within one object.

看来大多数情况下,还是只能使用SetTransOjbect......

#10


使用OLEDB连接,在DW的UPDATE()之前,要把autocommit设为FALSE,commit或rollback后再设为TRUE,如果用SetTrans,看帮助里面写的是自动commit或rollback,是不是也需要手动改变autocommit值呢。。。

#11


那麼我们把问题再延深一下,类似,用SQL SERVER作后台数据库服务器,同一套PB程式,可以同时运行在几个工作站上存取同一个数据库裡的同一张表.
例如:一套考勤软件运行在20个工作站上,刚好这20个工作站的使用人员都需要请假,所以他们在不经意间同时运行了考勤软件,这时候PB裡的DW是否有能力处理这同时的20笔业务?

我是新来的,在这裡向各位报道一下~

#12


20个工作站不算多吧

#13


应该还是存在排队的问题吧~~~

#14


用事务控制

#1


pb也可以
不用的时候可以用disconnect来断开,与.net的close一样的.

#2


当然可以使用Disconnect断开,不过释放资源时效率肯定会差些,不过有得必有失,这是正常的。

#3


disconnect

#4


主要是这么操作带来的效率低下,哪个更符合应用的要求呢?
毕竟大部分时候在操作数据库,每次连接要花费不少的时间啊。。。

#5


可否把两种方案中合一下,比如在打开应用程序时"connect"改为在打开特定窗口时'connect';如果数据量较小;直接把数据取到前台操作;后断开数据库等等

#6


可以  在设置事务对象时用  setTrans (sqlca), 不用 setTransObject (sqlca)

setTransObject (sqlca)是一直连接

setTrans (sqlca)在执行的时候自动在连接,执行完毕后自动释放资源,适合连接数目大的系统

#7


SetTransObject versus SetTrans  In most cases, use the SetTransObject method to specify the transaction object because it is efficient and gives you control over when transactions are committed.

The SetTrans method provides another way of managing the database connection. SetTrans, which sets transaction information in the internal transaction object for the DataWindow control or DataStore, manages the connection automatically. You do not explicitly connect to the database; the DataWindow connects and disconnects for each database transaction, which is less efficient but necessary in some situations.

#8


可以  在设置事务对象时用  setTrans (sqlca), 不用 setTransObject (sqlca)

setTransObject (sqlca)是一直连接

setTrans (sqlca)在执行的时候自动在连接,执行完毕后自动释放资源,适合连接数目大的系统

对,如果真要这么做我建议用这种方法

#9


把PB的帮助拿出来翻了一下
You must use SetTransObject with DataWindow objects that use the Composite presentation style. Composite DataWindows are containers for other DataWindow objects and do not have any internal transaction information of their own.

If you use SetTrans with each nested DataWindow in a composite DataWindow, disconnect does not occur until the PowerBuilder session ends. 
Use SetTrans when you want PowerBuilder to manage the database connections automatically because you have a limited number of available connections or will be using the application from a remote location. SetTrans is appropriate when you are only retrieving data and do not need to hold database locks on records the user is modifying. However, for better performance, you should use SetTransObject.

When you use SetTrans to specify the transaction object, you cannot update multiple DataWindow objects or multiple tables within one object.

看来大多数情况下,还是只能使用SetTransOjbect......

#10


使用OLEDB连接,在DW的UPDATE()之前,要把autocommit设为FALSE,commit或rollback后再设为TRUE,如果用SetTrans,看帮助里面写的是自动commit或rollback,是不是也需要手动改变autocommit值呢。。。

#11


那麼我们把问题再延深一下,类似,用SQL SERVER作后台数据库服务器,同一套PB程式,可以同时运行在几个工作站上存取同一个数据库裡的同一张表.
例如:一套考勤软件运行在20个工作站上,刚好这20个工作站的使用人员都需要请假,所以他们在不经意间同时运行了考勤软件,这时候PB裡的DW是否有能力处理这同时的20笔业务?

我是新来的,在这裡向各位报道一下~

#12


20个工作站不算多吧

#13


应该还是存在排队的问题吧~~~

#14


用事务控制