PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > isolation level
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
isolation level

Réponse
 
LinkBack Outils de la discussion
Vieux 03/09/2008, 17h52   #1
shripaldalal
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut isolation level

Hi,

using sql server 2000 with classic asp

have a table with a field "series count"

every invoice made will have an incrementing series count

so when everytime an invoice is made:

conn.begintrans
set rs = conn.execute("select series_count from table1") ' one field /
one record in table1
count = rs(0) + 1
inv_number = count
conn.execute("update table1 set series_count = " & count) ' only one
record in table, set new val

if err.number <> 0 then conn.rollbacktrans else conn.committrans

till now i used to use this on an ms access database and i have never
had a problem
it's worked wonderfully, isolation level is READ COMMITTED

now i am going to use this on sql server 2000 whose isolation level is
READ COMMITTED by default.... there will be 100's of ppl using the
site at the same time.....is READ COMMITTED fine for the above code to
work or should I use SERIALIZATION ?

best regards,
shripal.
  Réponse avec citation
Vieux 03/09/2008, 22h35   #2
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: isolation level

On 03.09.2008 17:52, shripaldalal wrote:
> Hi,
>
> using sql server 2000 with classic asp
>
> have a table with a field "series count"
>
> every invoice made will have an incrementing series count
>
> so when everytime an invoice is made:
>
> conn.begintrans
> set rs = conn.execute("select series_count from table1") ' one field /
> one record in table1
> count = rs(0) + 1
> inv_number = count
> conn.execute("update table1 set series_count = " & count) ' only one
> record in table, set new val
>
> if err.number <> 0 then conn.rollbacktrans else conn.committrans
>
> till now i used to use this on an ms access database and i have never
> had a problem
> it's worked wonderfully, isolation level is READ COMMITTED
>
> now i am going to use this on sql server 2000 whose isolation level is
> READ COMMITTED by default.... there will be 100's of ppl using the
> site at the same time.....is READ COMMITTED fine for the above code to
> work or should I use SERIALIZATION ?


Change your approach. Either use an autoincrement column and
SCOPE_IDENTITY (if you can live with holes in the sequence caused by
rolled back transactions) or store the counter in a separate table and
do an UPDATE with an OUTPUT clause to return the incremented value. But
note that the latter approach is a potential bottleneck if there are
multiple concurrent accesses and / or transactions are long lived.

Kind regards

robert
  Réponse avec citation
Vieux 04/09/2008, 02h57   #3
Sylvain Lafontaine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: isolation level

No, it's not. The Read Committed transaction isolation level doesn't
prohibit two different connections to read the same value of series_count
before the update take place. The probality is low but not zero. As you
are on SQL-Server 2000, you should use a single update statement; something
like:

declare @i int;
update table1 set @i = series_count = (series_count + 1) where IdTable = 1;
select @i;

You can execute this in a single Conn.Execute statement because it will be a
single batch. For the above statement, Read Commited will now be sufficient
because the update take place in the same instruction as the reading and the
update lock will be held until the end of the transaction.

Notice that in a professional database, this is still insufficient because
there is a possibility of having hole in your system is there is any problem
later in the client's code. In a real application, the creation of
additional records into the tables should be done inside the same
transaction - possibly with a flag indicating that this record has just been
created but has yet to be used - in order to ensure that there will be no
hole (a legal requirement in some countries).

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"shripaldalal" <shripaldalal@gmail.com> wrote in message
news:9d1c6f56-be7f-486c-a841-0ede66ef0e07@i24g2000prf.googlegroups.com...
> Hi,
>
> using sql server 2000 with classic asp
>
> have a table with a field "series count"
>
> every invoice made will have an incrementing series count
>
> so when everytime an invoice is made:
>
> conn.begintrans
> set rs = conn.execute("select series_count from table1") ' one field /
> one record in table1
> count = rs(0) + 1
> inv_number = count
> conn.execute("update table1 set series_count = " & count) ' only one
> record in table, set new val
>
> if err.number <> 0 then conn.rollbacktrans else conn.committrans
>
> till now i used to use this on an ms access database and i have never
> had a problem
> it's worked wonderfully, isolation level is READ COMMITTED
>
> now i am going to use this on sql server 2000 whose isolation level is
> READ COMMITTED by default.... there will be 100's of ppl using the
> site at the same time.....is READ COMMITTED fine for the above code to
> work or should I use SERIALIZATION ?
>
> best regards,
> shripal.



  Réponse avec citation
Vieux 05/09/2008, 10h47   #4
shripaldalal
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: isolation level

Hi, so is serialization good enough for this job ? the number that i
get i concatenate it like inv/ + (number i get) and put it in the
table in a field where no duplicates are allowed so the good thing is
by any chance even if there's a duplicate number one of the
transactions will generate an error and get rolled back, but if
serialization is best for this job i dont mind using that for this
job..... should i use serialization ?

On Sep 4, 5:57am, "Sylvain Lafontaine" <sylvain aei ca (fill the
blanks, no spam please)> wrote:
> No, it's not. The Read Committed transaction isolation level doesn't
> prohibit two different connections to read the same value of series_count
> before the update take place. The probality is low but not zero. Asyou
> are on SQL-Server 2000, you should use a single update statement; something
> like:
>
> declare @i int;
> update table1 set @i = series_count = (series_count + 1) where IdTable = 1;
> select @i;
>
> You can execute this in a single Conn.Execute statement because it will be a
> single batch. For the above statement, Read Commited will now be sufficient
> because the update take place in the same instruction as the reading and the
> update lock will be held until the end of the transaction.
>
> Notice that in a professional database, this is still insufficient because
> there is a possibility of having hole in your system is there is any problem
> later in the client's code. In a real application, the creation of
> additional records into the tables should be done inside the same
> transaction - possibly with a flag indicating that this record has just been
> created but has yet to be used - in order to ensure that there will be no
> hole (a legal requirement in some countries).
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: sylvain aei ca (fill the blanks, no spam please)
>
> "shripaldalal" <shripalda...@gmail.com> wrote in message
>
> news:9d1c6f56-be7f-486c-a841-0ede66ef0e07@i24g2000prf.googlegroups.com...
>
>
>
> > Hi,

>
> > using sql server 2000 with classic asp

>
> > have a table with a field "series count"

>
> > every invoice made will have an incrementing series count

>
> > so when everytime an invoice is made:

>
> > conn.begintrans
> > set rs = conn.execute("select series_count from table1") ' one field /
> > one record in table1
> > count = rs(0) + 1
> > inv_number = count
> > conn.execute("update table1 set series_count = " & count) ' only one
> > record in table, set new val

>
> > if err.number <> 0 then conn.rollbacktrans else conn.committrans

>
> > till now i used to use this on an ms access database and i have never
> > had a problem
> > it's worked wonderfully, isolation level is READ COMMITTED

>
> > now i am going to use this on sql server 2000 whose isolation level is
> > READ COMMITTED by default.... there will be 100's of ppl using the
> > site at the same time.....is READ COMMITTED fine for the above code to
> > work or should I use SERIALIZATION ?

>
> > best regards,
> > shripal.- Hide quoted text -

>
> - Show quoted text -

  Réponse avec citation
Vieux 05/09/2008, 18h42   #5
Sylvain Lafontaine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: isolation level

> Hi, so is serialization good enough for this job ? the number that i
> get i concatenate it like inv/ + (number i get) and put it in the
> table in a field where no duplicates are allowed so the good thing is
> by any chance even if there's a duplicate number one of the
> transactions will generate an error and get rolled back, but if
> serialization is best for this job i dont mind using that for this
> job..... should i use serialization ?


Seriously, I'm not sure to understand what you're saying here but if all you
want is a Yes/No answer than yes, serialization is good for your case and
you should use serialization.

However, I would suggest that you read more carefully my previous post and
also that you start a few days of serious study about transactions,
isolation levels and lockings. In my opinion, not having a clear
understanding of these mecanism is a no-go if you want to work with
SQL-Server.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"shripaldalal" <shripaldalal@gmail.com> wrote in message
news:430065d4-72c2-4545-b7a8-de068a734275@b2g2000prf.googlegroups.com...
Hi, so is serialization good enough for this job ? the number that i
get i concatenate it like inv/ + (number i get) and put it in the
table in a field where no duplicates are allowed so the good thing is
by any chance even if there's a duplicate number one of the
transactions will generate an error and get rolled back, but if
serialization is best for this job i dont mind using that for this
job..... should i use serialization ?

On Sep 4, 5:57 am, "Sylvain Lafontaine" <sylvain aei ca (fill the
blanks, no spam please)> wrote:
> No, it's not. The Read Committed transaction isolation level doesn't
> prohibit two different connections to read the same value of series_count
> before the update take place. The probality is low but not zero. As you
> are on SQL-Server 2000, you should use a single update statement;
> something
> like:
>
> declare @i int;
> update table1 set @i = series_count = (series_count + 1) where IdTable =
> 1;
> select @i;
>
> You can execute this in a single Conn.Execute statement because it will be
> a
> single batch. For the above statement, Read Commited will now be
> sufficient
> because the update take place in the same instruction as the reading and
> the
> update lock will be held until the end of the transaction.
>
> Notice that in a professional database, this is still insufficient because
> there is a possibility of having hole in your system is there is any
> problem
> later in the client's code. In a real application, the creation of
> additional records into the tables should be done inside the same
> transaction - possibly with a flag indicating that this record has just
> been
> created but has yet to be used - in order to ensure that there will be no
> hole (a legal requirement in some countries).
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: sylvain aei ca (fill the blanks, no spam please)
>
> "shripaldalal" <shripalda...@gmail.com> wrote in message
>
> news:9d1c6f56-be7f-486c-a841-0ede66ef0e07@i24g2000prf.googlegroups.com...
>
>
>
> > Hi,

>
> > using sql server 2000 with classic asp

>
> > have a table with a field "series count"

>
> > every invoice made will have an incrementing series count

>
> > so when everytime an invoice is made:

>
> > conn.begintrans
> > set rs = conn.execute("select series_count from table1") ' one field /
> > one record in table1
> > count = rs(0) + 1
> > inv_number = count
> > conn.execute("update table1 set series_count = " & count) ' only one
> > record in table, set new val

>
> > if err.number <> 0 then conn.rollbacktrans else conn.committrans

>
> > till now i used to use this on an ms access database and i have never
> > had a problem
> > it's worked wonderfully, isolation level is READ COMMITTED

>
> > now i am going to use this on sql server 2000 whose isolation level is
> > READ COMMITTED by default.... there will be 100's of ppl using the
> > site at the same time.....is READ COMMITTED fine for the above code to
> > work or should I use SERIALIZATION ?

>
> > best regards,
> > shripal.- Hide quoted text -

>
> - Show quoted text -



  Réponse avec citation
Vieux 06/09/2008, 11h07   #6
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: isolation level

On 05.09.2008 18:42, Sylvain Lafontaine wrote:
> However, I would suggest that you read more carefully my previous post and
> also that you start a few days of serious study about transactions,
> isolation levels and lockings. In my opinion, not having a clear
> understanding of these mecanism is a no-go if you want to work with
> SQL-Server.


Absolutely agree! Not taking the time to understand the concepts
properly and how SQL Server implements them is a recipe for disaster.
And this is true for other databases as well since there are remarkable
differences between products in this area despite the "simple" theory.

Kind regards

robert
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h51.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17269 seconds with 14 queries