473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sqlTransaction Complete Problem-dataype change from image to varbi

Hi,

This is being called in a C# loop within an ado.net transaction from C# 1.1
code. It is used to write large file data to a SQL Server database in
chunks, rather than in one go.

I had the stored procedure below, which worked until the image datatype was
changed to varbinary(max).

Now I get the following error:

This SqlTransaction has completed; it is no longer usable

The stored procedure is here (NOTE this is the version that works with the
dataype set to image. If I change the datatype to varbinary(max), and
obviously change the field in the table as well, the code fails with the
error given above).

ALTER PROCEDURE [dbo].[FileUploadData_ Upd]
@FileID Uniqueidentifie r,
--@data varbinary(max),
@data image,
@append bit
AS

SET NOCOUNT ON
IF @append = 0
UPDATE dbo.FileUpload
SET Data = @data
WHERE FileId = @FileID;
IF @append = 1
UPDATE dbo.FileUpload
SET Data.write(@dat a,NULL,0)
Any help would be appreciated

--
Regards,

Phil Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
Jan 23 '08 #1
15 3160
I should add, I have modified the datatype of the parameter in C# to be
varBinary:

SqlParameter paramData = cm.Parameters.A dd("@data",
System.Data.Sql DbType.VarBinar y);

And the isolation level of the transaction is ReadCommitted.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
"Phil Johnson" wrote:
Hi,

This is being called in a C# loop within an ado.net transaction from C# 1.1
code. It is used to write large file data to a SQL Server database in
chunks, rather than in one go.

I had the stored procedure below, which worked until the image datatype was
changed to varbinary(max).

Now I get the following error:

This SqlTransaction has completed; it is no longer usable

The stored procedure is here (NOTE this is the version that works with the
dataype set to image. If I change the datatype to varbinary(max), and
obviously change the field in the table as well, the code fails with the
error given above).

ALTER PROCEDURE [dbo].[FileUploadData_ Upd]
@FileID Uniqueidentifie r,
--@data varbinary(max),
@data image,
@append bit
AS

SET NOCOUNT ON
IF @append = 0
UPDATE dbo.FileUpload
SET Data = @data
WHERE FileId = @FileID;
IF @append = 1
UPDATE dbo.FileUpload
SET Data.write(@dat a,NULL,0)
Any help would be appreciated

--
Regards,

Phil Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
Jan 24 '08 #2
Can you post the C# loop code at all?

Marc
Jan 24 '08 #3
Oops; forgot the throw! Very important... ;-p

catch {
tran.Rollback() ;
throw;
}

Marc
Jan 24 '08 #4
And just to show how TransactionScop e makes life easier:

using (SqlCommand cmd = conn.CreateComm and())
using (TransactionSco pe tran = new TransactionScop e()) {
// ...SNIP... (everything)
tran.Complete() ;
}
Jan 24 '08 #5
The one thing I'm not seeing in the code is anything to do with a
transaction...? Where is this transaction? Is it an ambient
(TransactionSco pe) transaction?

I altered my original SQL2000 code from here:
http://groups.google.co.uk/group/mic...4e7e3782e59a93

(with the changes as per the previous 2 posts), and it worked fine for
both SqlTransaction and TransactionScop e?

So the transaction that appears to be closing itself: where is this
declared?
It is perhaps in a freaky orphan state, and the GC.Collect() is making
it call the finalize, hence tear down the transaction?

(in which case, don't let it get orphaned! If this is the problem, the
GC.Collect(), although unusual, has probably (by chance) just saved
you from a hard to track bug).

Marc
Jan 24 '08 #6
I suspect you're going to have to take pieces away until it
breaks...
Of course, I meant the other way around: start with something simple
that works, and keep adding pieces *in* until it breaks. It works fine
here...

Marc
Jan 24 '08 #7

Thanks for the help anyway Marc,

I will probably have to do as you say and start with the simplest form and
keep building up on it.

Its a sticky one... If I find out what is causing the problem I will add
another reply here.

Thanks again for your time

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
"Marc Gravell" wrote:
I suspect you're going to have to take pieces away until it
breaks...

Of course, I meant the other way around: start with something simple
that works, and keep adding pieces *in* until it breaks. It works fine
here...

Marc
Jan 24 '08 #8
If I find out what is causing the problem I will add
another reply here.
Please do; I'm genuinely interested in what is going wrong - because
(obviously) this is something I need to do occasionally.

Marc
Jan 24 '08 #9
I think it is the size of the buffer... I cut it back to 8040 rather than
8040000 and it started going throught the loop again and again rather than
quiting the second time through.

I was trying a 100MB file and it killed my machine though.... I will try
other sizes when I get back in the office tomorrow to try to find an optimum
size but early indications are that is going to get it.

Thanks again for your help, its greatly appreciated.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
"Marc Gravell" wrote:
If I find out what is causing the problem I will add
another reply here.

Please do; I'm genuinely interested in what is going wrong - because
(obviously) this is something I need to do occasionally.

Marc
Jan 24 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2043
by: mahajan.sanjeev | last post by:
I have two SQLConnection objects having the same connection string and two corresponding SQLCommand objects for each connection object. I am using SQLTransaction with the first SQLConnection object but the second SQLConnection object does not have any SQLTransaction object. I am inserting some data using the two command objects. The problem...
2
2796
by: mahajan.sanjeev | last post by:
Hi, I am having problems with rollback using the SQLTransaction object. I am trying to insert records in two tables in a transaction. I want to rollback all the changes if any exception occurs in any of the inserts. But the SQLTransaction object only rolls back the inserts that happen before an exception. All inserts after the exception go...
0
1069
by: mahajan.sanjeev | last post by:
Hi All, I am using a SQLTransaction in a .Net application to insert records into a SQL Server table. At one time, there are 5000 or more records to be inserted one by one. It takes some 20-25 mins for the entire process to run. Another application accesses the same table. As long as the insert process within the transaction isn't...
0
1492
by: perspolis | last post by:
Hi all I used SqlTransaction inmy application.. SqlTransaction transact=sqlConnection1.BeginTransaction(IsoLationLevel.Something); sqlSelect.Transaction=transact; sqlInsert.Transaction=transact; ,............... but any of IsolationLevel stat I use it dosen't work properly and it works as Serializable isolation level.. When I'm using a...
2
2752
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the information into three separate tables (all in a single aspx page -- without using stored procedures, yet). The first SQL Statement accepts the...
0
1032
by: Joe Rigley | last post by:
Hi All, I am using a SqlTransaction object to process a group of database insert / update statements on Sql Server 200 SP4 to complete a business process. Directly after the Commit method is issued, I perform a select on one of the tables that was inserted into during the SqlTransaction process. Unfortunately, the select statement does...
5
451
by: Swami Muthuvelu | last post by:
Hi, I using command builder to generate my insert, update and delete statements..something like, data_adapter = New SqlClient.SqlDataAdapter(SQL, ActiveConnection) command_builder = New SqlClient.SqlCommandBuilder (data_adapter)
3
1291
by: Neven Klofutar | last post by:
Hi, I'm trying to retrieve some information from DB using SqlTransaction, but I have a problem. I'm executing some DELETE SQL statements using Transaction. Then later on (because of the lousy project) I need to read the same information from DB that is beeing deleted using the same transaction. Is it possible to delete data, and read the...
4
2894
by: perspolis | last post by:
Hi all I have a master-detail tables in sql server. I use SqlTransaction to insert data into both tables. it works well but if I check the "Cascade Delete Related Records" option in it's realtion in sql server my SqlTransaction dosen't work and get timeout error.. please help me thanks in advance
3
3118
MrMancunian
by: MrMancunian | last post by:
Ok, I'm stuck on a design problem and I need some feedback how to go around it. CASE: Pathologists can request stains on certain tissues. It's possible to request more than one stain a time. The program where they make these requests (which is third-party software) creates an XML-file for one stain. So, if two stains are requested on one...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.