Showing posts with label constraints. Show all posts
Showing posts with label constraints. Show all posts

Friday, March 30, 2012

How to trap the results of constraints in SQL Server 2005from Visual studio C# Code?

Hi all,

Suppose I have set a CHECK constraint to a column where Salary field is not permitted to be less than 1000 or greater than 10000.

In this situation, when I insert a new record with salary as 10, using a stored procedure from Visual Studio, how will I trap the error from C# Code?

Thanks

Tomy

Your best bet would be to have layered constraints. Your business logic should also make sure that the data being entered is between 1000 and 10000, so that the violation would never reach the database. Database constraints should be left in place for people who like to edit the database directly.

While you can get a violated constraint error from the database, I don't believe it would be phrased properly to display to your users, which would mean lots of parsing in order to make the error presentable and user-friendly. It would be better to use a range validator to prevent the user from entering incorrect information.

As for trapping the error, use Try/Catch blocks

try{}catch (System.Data.SqlClient.SqlException ex){// Handle SQL Exceptions here; // all sql exceptions fall under this exception type, // but the errorcode/errors will be different.}catch (Exception ex){// handle all other errors here.}
|||

Thanks a lot.

Wednesday, March 28, 2012

How to Translate an Oracle DataBase to SQL Server DataBase with constraints and

Hello,

Mr. rnealejr:
I use MS SQL Server 2000.
Also, I have a problem with SQL Server.
I have about 50 tables and views in an Oracle DataBase and I have tried to translate them to SQL Server DataBases.
They were translated succefully but there was two problems :
1- Key constraints were not translated? (i.e. the destination SQL Server database became without primary key and foreign key constraints and aother constraints)
2- Also, views are translated into tables not into view ??

Could you slove these problems?

After I get more information I will be able to serve your good forum with good posts becuase until now I am student

Thank you very much

ShihabMaybe you can 'reverse engineer' the Oracle database with a data modelling tool (e.g. ERwin) and then 'forward engineer' that schema to SQL Server.
I don't know whether views also can go through this trajectory, but since the syntax of creating views is the same (although SQL Server 2000 doesn't do the create or replace trick) you can build these views from the statements you can see within the Oracle Enterprise Manager or TOAD. Save the creation statements of both the tables, constraints and views in a script. You'll always need it at least once.

Edwin|||Originally posted by edwin
Maybe you can 'reverse engineer' the Oracle database with a data modelling tool (e.g. ERwin) and then 'forward engineer' that schema to SQL Server.
I don't know whether views also can go through this trajectory, but since the syntax of creating views is the same (although SQL Server 2000 doesn't do the create or replace trick) you can build these views from the statements you can see within the Oracle Enterprise Manager or TOAD. Save the creation statements of both the tables, constraints and views in a script. You'll always need it at least once.

Edwin

I am very sorry, I don't understand what you mean by 'reverse engineer' and 'forward engineer'
Could you clearify these terms ??
Thank you very much|||"reverse engineer" "forward engineer" (http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=%22reverse+engineer%22++%22forward+engineer%22)

rudy
http://rudy.ca/