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 3336426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:08:01+00:00 2026-05-18T00:08:01+00:00

I have a Users table, which has a Unique constraint on the username (for

  • 0

I have a Users table, which has a Unique constraint on the username (for obvious reasons).

I am using an EF 4.0 DAL to populate the database, and in the process of coding the CreateUser() method.

Is it…

  1. Best to catch the SqlException thrown if I try to insert a username which already exist.
  2. Explicitly check for the username before I try to insert it to the database?

If you could also give reasons as to why, that would be great!

  • 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-18T00:08:02+00:00Added an answer on May 18, 2026 at 12:08 am

    I would check if the record exists first. Unique key constraints are useful to guard against possible ways your application is allowing “bad” data through in the first place, but not the main stop for that. It’s generally a bad idea to use exceptions as a control flow mechanism (validation in this case) when it’s possible to avoid.

    EDIT: To avoid confusion, I’m not saying don’t have the unique index at all. It should be there, but it shouldn’t be the primary means of checking for uniqueness.

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

Sidebar

Related Questions

So I have a mySQL database with a 'users' table which includes a username,
I have a table users which has a primary key userid and a datetime
I have an application which has a Projects table and a Users table. In
Suppose we have a table Users that has only one column UserId which is
We have a user table, every user has an unique email and username. We
Another question which has me perplexed: I have a table which enables users to
Say I have an SQL table that has a unique key (or other) constraint
I have a User table which has a PrivilegeId foreign key points to a
I have a table User which has the fields (id, first_name, middle_name, last_name). I
I have a table in HTML which has three columns i.e Error - User

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.