Simple Response. Redirect error in dll file! plz help

  • Thread starter Thread starter Shawn Convington
  • Start date Start date
S

Shawn Convington

Hey,
I am facing a problem which seems srange to me. I have a simple dll
class file i have created in its own projected, so it can be inherited
and used by others (for example security.dll here).

I have a method here whhich takes the sql statement the sql string and
returns the result from database as dataset.


Here is the code:

/**************
public DataSet ExceuteDataSetQuery(string sqlProcedure)
{
//returns dataset reults depending upon the stored procedure
or view called from database

objConn = new SqlConnection(_connectionString);
DataSet ds = new DataSet();
myAdapter = new SqlDataAdapter(sqlProcedure, objConn);

try
{
objConn.Open();
myAdapter.Fill(ds);
}
catch (Exception ex)
{
_message = ex.ToString();

}


objConn.Close();
return ds;

}
***************/

it works like charm, but i am kinda lost on what to do if error happens
and user is sent to catch block.
I try to use Response.Redirect("errorPage.aspx"), but that doesn't
work, it is not recognizinf repponse.redirect here! Eventhough, I have
inherited all the right classes correctly...

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;

i dont know what else to do, also it does recognize the simple session
messages wither. Session["Userid"]=33 for example.
Do we have limit when we are compiling and creating cs files as dll
files? If yes, then it seems strange to me, let me know thanks

shawn
 
I might want to check your _message with is "" in your aspx page then you
will know whether the error has occurred.

chanmm
 
Since your class is not part of the web project, it will not have a
reference to the current HttpContext. You will need to reference the
Response object like:

System.Web.HttpContext.Current.Response


However.. Since you put this in its own .dll (so others can use it),
you are not guaranteed that it will be used from a web app. It could
be used from a windows form and the Response.Write will bomb.

You would be better off throwing an exception that the consumer of
your object will be able to catch and handle the error appropriately.
 
Back
Top