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

  • SEARCH
  • Home
  • 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 545841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:48:16+00:00 2026-05-13T10:48:16+00:00

SQL Server 10, .NET, C# This is similar to this question but not exactly

  • 0

SQL Server 10, .NET, C#

This is similar to this question but not exactly the same.

When a user creates new event on my event-scheduling web site, a unique sort-of easy to remember code is to be generated, so this code can be communicated (via the phone, let’s say) to the participants. This generated code looks something like:

JohMonBlue5
<abbriviated name><abbriviated week day><some uniquefying suffix><index>

Yes, I could just e-mail a link, but I suppose that’s not an option.

Note: I chose to use uniquefying suffix that is a color, since I think it’s easier to remember color, than a number. Still I use number in case of a collision.

Question: What’s a good way to implement this (I have unique constraint on the column already):

  1. I can generate the index on the app side, and use try { insert } catch { retry }. In this case, how do I tell “Duplicate column value” exception from any other exception? by message text?
  2. Use something in the MSSQL Server to increment trailing number until uniqueness reached.
  • 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-13T10:48:16+00:00Added an answer on May 13, 2026 at 10:48 am

    I suggest not using the catch to handle your duplicates exclusively. Catch should only be used for true errors and besides that, exception catching is slow and expensive. It would be better to generate a value and test to see whether it already exists via a query rather than allowing an exception to get thrown.

    I would also implement the generator in one place. Don’t split it by creating a color on the client and the number in the db. Pick one side or the other. On the Sql Server side a good way of implementing this type of feature is to use a UDF. Perhaps you can create a table of keywords (colors in your case) and randomly select from it and then perform your increment for uniqueness.

    I also think that you don’t have to o colors exclusively. Choose any words that are simple and easy to remember. Dragon, Friday, Blue, House…

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

Sidebar

Related Questions

This past summer I was developing a basic ASP.NET/SQL Server CRUD app, and unit
I asked a similar question on how to do this on the server side
I am running windows server with asp.net websites and sql server 2008 and IIS
I'm trying to drop a SQL Server database from .NET code. I've tried using
I'm using WCF, SQL Server and ADO.NET. I'm looking at two implementation options for
At my current job we have a CMS system that is .NET/SQL Server based.
I'm looking to add an advanced search capability to my ASP.NET/SQL Server 2005 application.
SQL Server a stored procedure written in C# on the .NET 2.0 framework that
Using VB.NET and SQL Server 2005 In my software I am using login page
Using SQL Server 2005 and VB.Net Table1 ID Name Dept 001 Raja IT 002

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.