Home > Net >  C # Guid. NewGuid () generated Guid repeat, how to solve?
C # Guid. NewGuid () generated Guid repeat, how to solve?

Time:10-03

Take over a project, database using GUID family bond, the GUID is WCF code generation inside the , but sometimes will repeat,

The foreach (var itemRow orderDT) in
{
If (itemRow. RowState==DataRowState. Added)
{
ItemRow. OrderID=Guid. NewGuid ();
ItemRow. EndEdit ();
}
}

Online to find the solution: make database automatically generated, but I look at the next project, and the other is to change, don't want to work overtime,

Want to ask next recognize there are other ways?

CodePudding user response:

Sometimes repeat,,,
Sound has a lot of times you repeat?
But the guid the probability of repeated should very, very small,
If the code problem?

CodePudding user response:

Normal should be running one or two months to have a few repetitions, you in the preservation and a try catch, not inbound repeated by the uniqueness of database constraints

CodePudding user response:

reference 1st floor is nu month god reply:
sometimes repeat,,,
Sound has a lot of times you repeat?
But the guid the probability of repeated should very, very small,
If the code problem?




Code added inside the try catch is repeated with high now, live a few days to repeat, tip need to save every time, and
Don't know whether this writing has a problem,

The foreach (var itemRow orderDT) in
{
If (itemRow. RowState==DataRowState. Added)
{
//WCF generates the Guid
ItemRow. OrderID=Guid. NewGuid ();
ItemRow. EndEdit ();
}
}
//updates to the database
OrderTableAdapter OrderTableAdapter=new OrderTableAdapter ();
OrderTableAdapter. Update (orderDT);

CodePudding user response:

Probability is small, the order id to see can change to time + guid

CodePudding user response:

 var list1=new List (a); 
The info info1=new info ();
for (int i=0; I & lt; 3; I++)
{
List1. Add (info1);
}

The foreach (var item in list1)
{
Item. The department=Guid. NewGuid (). The ToString ();
}

This case assignment item. Department value the same guid, you check if there is a similar code assignment code

CodePudding user response:

If it is repeated to data query, if already exists, to regenerate

CodePudding user response:

Basically should be 100 years will not be repeated (even on the same machine), careful debugging, testing your application,

CodePudding user response:

reference asfadfsf reply: 3/f
code inside added a try catch is repeated with high now, live a few days to repeat, tip need to save every time, and
Don't know whether this writing has a problem,

The foreach (var itemRow orderDT) in
{
If (itemRow. RowState==DataRowState. Added)
{
//WCF generates the Guid
ItemRow. OrderID=Guid. NewGuid ();
ItemRow. EndEdit ();
}
}
//updates to the database
OrderTableAdapter OrderTableAdapter=new OrderTableAdapter ();
OrderTableAdapter. Update (orderDT);


"OrderID repeat" is the new record, or modify the record?

CodePudding user response:

You need to test and debug the duplicate records (in OrderTableAdapter OrderTableAdapter=new OrderTableAdapter () before the statement), according to repeat OrderID backstepping assignment before logic errors,

.net that won't be any error, should check your program logic error,

CodePudding user response:

Didn't understand what are you doing to
Now that is a primary key, can't have a little repeated
And how can guid repeat

CodePudding user response:

Look at this, orderly guid
https://www.cnblogs.com/slyzly/articles/9215629.html

CodePudding user response:

Guid in single case if you are right, will not repeat, within the same millisecond 1000

So the repeated problems, please check your own code production part,

CodePudding user response:

You should write their own test and debug, has nothing to do with the database, c # code to find you in the call DbAdapter. Update statement before the so-called OrderID bug, if what is blind with "online to find the solution: make database automatically generated", so it is quite blind, is not careful to grasp the development process, you should find a c # code bug, personally know. Which one statement specifically reflects the.net framework has a bug, and Microsoft to receive $100000 prize, which is the programmer should do, and only takes 10 minutes time, find a bug, not randomly change doesn't say what don't want to work overtime,

CodePudding user response:

refer to the second floor she would play the soy sauce response:
should be running normal one or two months to have a repeated several times, in the preservation, add a try catch you through database uniqueness constraints not warehousing repeat

Repetition rate so high? I think there are many website system, is with the guid is done advocate key,

CodePudding user response:

This code is run on the same machine?
Or... In the network to run on different machines,

Though the problem is a bit low, but still ask

CodePudding user response:

reference 15 floor fly4free response:
this code is run on the same machine?
Or... In the network to run on different machines,

Though the problem is a bit low, but still ask

I mean we question is a bit low,




Can't edit reply? Delete the also not line?

CodePudding user response:

refer to the 13th floor interacting in a professional developer response:
you should write their own test, and debug, has nothing to do with the database, c # code to find you in the call DbAdapter. Update statement before the so-called OrderID bug, if what is blind with "online to find the solution: make database automatically generated", so it is quite blind, is not careful to grasp the development process, you should find a c # code bug, personally know. Which one statement specifically reflects the.net framework has a bug, and Microsoft to receive $100000 prize, this is the programmer should do, and only takes 10 minutes time, find a bug, not randomly change not what to say "don't want to work overtime,"


The.net framework is a bug, I found, 100% is a bug

CodePudding user response:

Guid is generated in the network card MAC and timestamp,
So in your loop try to sleep

CodePudding user response:

refer to 17th floor orange peel ZZZ response:
Quote: refer to the 13th floor interacting in a professional developer response:

You should write their own test and debug,
  •  Tags:  
  • C#
  • Related