trying to generate a concurrency exception

G

Guest

but I am trying to generate a DBConcurrenyException to at least put up a
warning message to the user if a database table has been changed by another
user before being updated by this user.

data table-for each new record inserted the web app increments column 1.
***********************
* int * varchar (20) *
***********************
* abc3 * ted *
***********************
* def4 * tom *
***********************

I am performing a record read and then closing the connection and then
later performing an Insert as shown below. I tried performing the read with
one machine, then with another performing the read and insert and then went
back to the first machine to perform the insert (this is where I would want
to generate the exception), but it does not.

read portion - I use a stored procedure with select, data adapter and dataset.
Me.da_orig.Fill(Me.Ds_orig1, "dml$get_originator")

Insert portion - am not using a dataset
Dim da_dataitmlog As New SqlDataAdapter 'instance of class sqlDataAdapter
Dim cmd_dataitmlog As New SqlCommand("stored procedure")
da_dataitmlog.InsertCommand = cmd_dataitmlog
try
cmd_dataitmlog.ExecuteNonQuery() 'Executes the stored procedure
Catch dbcEx As Data.DBConcurrencyException
some other code
end try
thanks.
 
J

Jeppe Jespersen

Hi Paul,

Are you using the Data Adapter Configuration Wizard to create your
DataAdapter? If not, then why not. :) It actually does a fairly decent
job. And if you _do_ use the wiz, then could you post the commandtexts from
your commands or the contents of your stored procedures?

Jeppe Jespersen
Denmark
 
G

Guest

Hi Jeppe, thanks for the response. I did not use the data adapter wizard for
this portion, also using the execute nonquery member. Is there a data
adapter setting that I need to set to cause the DBConcurrencyException to
occure?
Paul.

Jeppe Jespersen said:
Hi Paul,

Are you using the Data Adapter Configuration Wizard to create your
DataAdapter? If not, then why not. :) It actually does a fairly decent
job. And if you _do_ use the wiz, then could you post the commandtexts from
your commands or the contents of your stored procedures?

Jeppe Jespersen
Denmark
 
J

Jeppe Jespersen

Hi Jeppe, thanks for the response. I did not use the data adapter wizard
for
this portion, also using the execute nonquery member. Is there a data
adapter setting that I need to set to cause the DBConcurrencyException to
occure?

No. The trick to the Adapter Wizard is that it generates commandTexts for
your commands that - when say, a "conflicting" update/insert/delete command
is executed - will automatically generate the concurrency exception for you.
Very effective, in fact. Check it out.

Jeppe Jespersen
Denmark
 
G

Guest

Hi Jeppe, thanks for the additional information. Unfortunately the wizard
creates code that does not build correctly for this particular case so had to
put in the code manually. Just wondering if you know if you can generate
the commandTexts manually and what this would be?
 
J

Jeppe Jespersen

Hi Jeppe, thanks for the additional information. Unfortunately the wizard
creates code that does not build correctly for this particular case so had
to
put in the code manually. Just wondering if you know if you can generate
the commandTexts manually and what this would be?

"generate manually"? you got me spinning here :)

Actually, if the Wizard-generated code doesn't do the trick, you'll have to
set the commands' commandText properties manually. At least as far as I
know. Sorry. :-(

Jeppe Jespersen
Denmark
 
G

Guest

Ok, thanks for the additional information.

Jeppe Jespersen said:
"generate manually"? you got me spinning here :)

Actually, if the Wizard-generated code doesn't do the trick, you'll have to
set the commands' commandText properties manually. At least as far as I
know. Sorry. :-(

Jeppe Jespersen
Denmark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top