Showing posts with label catching. Show all posts
Showing posts with label catching. Show all posts

Friday, February 24, 2012

Error catching on data duplication in a sql2005 db

Hello, everyone. I am having problems catching a data duplication issue. I hope I can get an answer in this forum. If not, I would appreciate it if someone can direct me to the right forum.

I am working on a vs2005 app which is connected to a sql2005 db. Precisely, I am working on a registration form. Users go to the registration page, enter the data, ie. name, address, email, etc. and submit to register to the site.

The INSERT query works like a charm. The only problem is that I am trying to reject registrations for which an email address was used. I put a constraint on the email field in the table and now if I try to register using an e-mail address that already exists in the database I get a violation error (only visible on the local machine) on the sql's email field, which is expected.

How can I catch that there is already an email address in the database and stop the execution of the code and possibly show a message to the user to use a different address?

Thank you for all your help.

Antonio

you could do something like this in a proc:

declare a parameter @.res of type OUTPUT.

IF NOT EXISTS ( SELET * FROM table WHERE Email = @.EMAIL)

BEGIN

--do the insert

SET @.res = 1

END

ELSE

BEGIN

SET @.res = 2

END

and use the value in @.res in your front end and displaty an appropriate message.

|||

Thank you dinakar. The SQL is working fine. I need help with the front-end. This issue was originally posted on the ASP.NET forum.

Antonio

|||

hi

here's sample code

SqlCommand cmd = new SqlCommand("CustOrderOne", cn);
cmd.CommandType=CommandType.StoredProcedure ;
SqlParameter parm=new SqlParameter("@.CustomerID",SqlDbType.NChar) ;
parm.Value="ALFKI";
parm.Direction =ParameterDirection.Input ;
cmd.Parameters.Add(parm);
SqlParameter parm2=new SqlParameter("@.ProductName",SqlDbType.VarChar);
parm2.Size=50;
parm2.Direction=ParameterDirection.Output;
cmd.Parameters.Add(parm2);
SqlParameter parm3=new SqlParameter("@.Quantity",SqlDbType.Int);
parm3.Direction=ParameterDirection.Output;
cmd.Parameters.Add(parm3);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
Response.Write(cmd.Parameters["@.ProductName"].Value);
Response.Write(cmd.Parameters["@.Quantity"].Value.ToString());

thanks,

satish

|||You could also use a TRY/CATCH block to catch any exceptions.

Error catching in SSIS

I have a package that is failing parsing a CSV file. I want to write the failing line to an error file and continue processing. I've added error output to the flat file source, that didn't work. I've added an onerror event handler to the data flow task, that didn't work. I've added an event handler to the package, that didn't work. How can i output the offending line but not have the process fail?

Go to the Error Output page on the Flat File Source editor and set appropriate Error and Truncation values to Redirect. After this connect your error output to a Flat file destination where you can take care of erroneous rows.

Thanks,

Bob

|||Thanks, but that isn't it. I've got it set to redirect. The error is

Error: 0xC0202055 at Data Flow Task, Flat File Source [1]: The column delimiter for column "Column 3" was not found.

It is being caused by an embeded double quote in the source CSV file. It's escaped to "" and the parser blows up. It dosent go to the error output. and i can't seem to catch the error, it kills the process.

|||

The flat file parser cannot handle embedded quotes. You will have to load qualified data and post-process it using script or derived columns.

Thanks,

Bob

Error catching in SSIS

I have a package that is failing parsing a CSV file. I want to write the failing line to an error file and continue processing. I've added error output to the flat file source, that didn't work. I've added an onerror event handler to the data flow task, that didn't work. I've added an event handler to the package, that didn't work. How can i output the offending line but not have the process fail?

Go to the Error Output page on the Flat File Source editor and set appropriate Error and Truncation values to Redirect. After this connect your error output to a Flat file destination where you can take care of erroneous rows.

Thanks,

Bob

|||Thanks, but that isn't it. I've got it set to redirect. The error is

Error: 0xC0202055 at Data Flow Task, Flat File Source [1]: The column delimiter for column "Column 3" was not found.

It is being caused by an embeded double quote in the source CSV file. It's escaped to "" and the parser blows up. It dosent go to the error output. and i can't seem to catch the error, it kills the process.

|||

The flat file parser cannot handle embedded quotes. You will have to load qualified data and post-process it using script or derived columns.

Thanks,

Bob