Showing posts with label accept. Show all posts
Showing posts with label accept. Show all posts

Wednesday, March 7, 2012

Exception.Data[key]=value

Hi.

Is it possible to transmit custom data from SQL 2005 to the client via Exception.Data[key]=value?

The idea
I have a number of SPs that accept userId parameter which must be verified. I have written a simple CLR SP (check_userid_valid) which performs the verification of the userId parameter's value. If the parameter's value is considered invalid an exception is thrown. When the exception (System.Exception) is instantiated additional data is added via the Data property of the exception:

System.Exception ex = new System.Exception();
ex.Data["Source"] = "check_userid_valid"

So, any SP that calls the check_userid_valid with invalid userId is expected to "crash" and the exception with all the additional data is expected to be propagated back to the client which, in turn, could read the data.
Unfortunately, it seems that the ex.Data contains only entries put by the MS SQL 2005 server itself, eliminating the rest.

The question is: how can I supply additional exception data with the exception I do throw from my CLR code on the server-side, so that is can be consumed at the client-side.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;


public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void CustomException()
{
try
{
//try code goes here
System.Exception firstEx = new System.Exception("first exception");
throw firstEx;
}
catch (System.Exception ex)
{

}
finally {
System.Exception secondEx = new System.Exception("check_userid_valid");
throw secondEx;
}
}
};

Sunday, February 19, 2012

Excel to SQL Server.

I would appreciate if any one can guide me or send me any stored procedure
through which I can accept the Excel file from User Interface, save it into
any physical folder or in the table and do some process and save the data
into the Database and also archive the excel file for future reference.
Thanks
"Roger" <naissani@.hotmail.com> wrote in message
news:OxLUPhIgHHA.3676@.TK2MSFTNGP05.phx.gbl...
>I would appreciate if any one can guide me or send me any stored procedure
>through which I can accept the Excel file from User Interface, save it into
>any physical folder or in the table and do some process and save the data
>into the Database and also archive the excel file for future reference.
As long as you have a consistent format for your xls, check out Data
Transformation Services (SQL Server 2000) or SQL Server Integration Services
(SSIS) (SQL Server 2005).
Steve