在单个连接中使用多个事务 [英] using multiple transactions in single connection

查看:423
本文介绍了在单个连接中使用多个事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上它是一种补丁机制


以下是我正在做的事情:

1.打开一个SQL连接。

2.开始交易。

3.更新数据库中的软件版本记录。

4.使用相同的数据库执行更多查询相同的连接。

5.下载15到20 MB的文件。

6.使用相同的连接执行选择查询。

7提交交易。

8.关闭交易。


这个序列导致SQL连接超时问题,因为下载文件需要时间。

问题是我只能在下载文件后才提交事务,而不是在此之前。


用C#编写代码。使用的数据库是SQLCE

以下是代码的一部分:


SqlCeConnection conn = new SqlCeConnection(" ConnectionString");

conn.Open();
$
SqlCeTransaction ts = conn.BeginTransaction();


//方法调用执行参数

(字符串sqlQuery,ref SqlCeConnection conn,SqlCeTransaction ts)

{

SqlCeCommand cmd = new SqlCeCommand();

cmd .Connection = conn;

cmd.Transaction = ts;

cmd.CommandText = sqlQuery;

cmd.ExecuteNonQuery();

}


//方法调用下载15到20 MB的文件


//方法执行一个选择查询通过使用相同的SQL连接返回软件的版本。


上面的查询给出了SQl连接超时的错误

ts.Commit();

conn.Close();




任何人都可以帮我解决问题

解决方案


如果可能,请避免在中间下载,不能在起点完成。如果要关闭并打开连接而不是sql事务,也可以使用事务范围。但我怀疑这可能导致同样的问题。


 


SQLCE不适用于实时交易。它仅适用于临时商店。


 


另外,使用不同的表副本执行所有更改,然后将处理后的数据复制到实际的表格。


 


Basically it's a patching mechanism

Here is what I'm doing :
1. Open a SQL connection.
2. Begin the transaction.
3. Update a record in database for the version of the software.
4. Execute some more queries on same database by using same connection.
5. Download a 15 to 20 MB file.
6. Execute a select query by using the same connection.
7. Commit the transaction.
8. Close the transaction.

This sequence is causing the problem of SQL Connection timeout as it takes time to download the file.
The problem is that I can commit the transaction only after downloading the file and not before that.

Writting the code in C#. Database used is SQLCE
Here is some part of the code:

SqlCeConnection conn = new SqlCeConnection("ConnectionString");
conn.Open();
SqlCeTransaction ts = conn.BeginTransaction();

//A method call executes all the methods that with parameters
(string sqlQuery, ref SqlCeConnection conn, SqlCeTransaction ts)
{
SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = conn;
cmd.Transaction = ts;
cmd.CommandText = sqlQuery;
cmd.ExecuteNonQuery();
}

//A method call downloads the file of 15 to 20 MB

//A method executes a select query that returns the version of the software by using same SQL connection.

The above query gives the error of SQl connection timeout
ts.Commit();
conn.Close();


Can any one help me to solve the problem

解决方案

Hi,

If possible avoid downloading in between, can't it be done at starting point. And also you can use transaction scope if you want to close and open a connection instead of sql transaction. But i suspect that could lead to same issue.

 

SQLCE is not ment for real time transaction. It is only for temporary store.

 

Otherway is to use a different table copy do all the changes and then copy the processed data to the actual table.

 


这篇关于在单个连接中使用多个事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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