Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6669035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:06:17+00:00 2026-05-26T03:06:17+00:00

My webapplication has a class WorkItem with a RecordID (Guid as Primary Key) and

  • 0

My webapplication has a class WorkItem with a RecordID (Guid as Primary Key) and a FriendlyID (string) that consists of Type-Date-RandomNumbers.

If I create a new WorkItem, I create a new FriendlyID as well.
The format of the FriendlyID cannot be changed (client specification) and is like <Type (one char)>-<Current Date (yyymmdd)>-<6 random numbers>.

private string GenerateFriendlyID()
{
    string res = String.Empty;
    // code omited
    // ...
    // IT'S NOT THE QUESTION HOW TO PROGRAM THIS METHOD!
    // It's about the fastest and best way/design to make 
    // sure the generated ID is unique! (see below)
    return res; // sth like "K-20110930-158349"
}

public override void Create()
{
    if (String.IsNullOrEmpty(friendlyID))
    {
        GenerateFriendlyID();
    }
    base.Create();
}

This code does fails under heavy load, so I get the same FriendlyIDs multiple times.
What is the best way to make sure that my friendly ID is unique?

  1. Make a UNIQUE-Constraint on FriendlyID in the DB.
    • Begin a transaction, generate a FriendlyID, insert and commit
    • Rollback and try again if I get a SQLException.
  2. Just create it.
    • Select all WorkItems with this.FriendlyID.
    • If selection is > 1, repeat until it’s == 1

I’m sure there is another way, but I guess #1 should be the preferred.

Are there any ways I’m missing or is #1 the way to go? I hate to use Exceptions for my workflow though and I know that they’re really slow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:06:18+00:00Added an answer on May 26, 2026 at 3:06 am

    My suggestion is in any case, whatever kind of id you want to generate, do this in the SQL in a stored procedure and not from .NET client code. It is always better to have an atomic entry point which takes some parameters and does the job, so you can call the stored and get your record saved and the id back to you as out parameter, even more than one, like a unique code and a guid.

    in this way, then, you move concurrency issues from the .NET client code to the Database Server and db servers are designed to handle concurrency well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm debbuging a web application that has a WebSite and a class library containg
I have a class library that has it's own model and connectionstring to the
I've written a helper class that takes a string in the constructor and provides
I created a WebApplication in NetBeans. It has a JSP page and a webservice.
My web application has a login page that submits authentication credentials via an AJAX
Other than the fact that ASP.NET MVC Web Application has more clarity in its
I have this web application that has grown to an unmanageable mess. I want
I have a web application that has a page that loads the content from
I have an .net assembly build against 3.5 framework. This assembly has a class
In docs: The key component there is a custom LogManager implementation, that is aware

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.