T
Tony Johansson
Hello!
When using ASP.NET(aspx page) I can use Respone.Write to send information to
the browser..
I know that it would be better to use Windows-application event handle log
but just for
learning assume that I want to send ex.Message to the browser when an
exception occur how can I do that.
I tested to use Respone.Write but that was not possible ?
[WebMethod]
public decimal HowMuchWillItCost(string productName, int howMany)
{
SqlConnection sqlConn = null;
try
{
ConnectionStringSettings cs =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"];
string connString = cs.ConnectionString;
sqlConn = new SqlConnection(connString);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = string.Format(@"select UnitPrice from Products
where productName = {0}", productName);
sqlCmd.Connection = sqlConn;
sqlConn.Open();
decimal price = (decimal)sqlCmd.ExecuteScalar();
return price * howMany;
}
catch (Exception ex)
{
return 1;
}
finally
{
if (sqlConn != null)
sqlConn.Close();
}
}
//Tony
When using ASP.NET(aspx page) I can use Respone.Write to send information to
the browser..
I know that it would be better to use Windows-application event handle log
but just for
learning assume that I want to send ex.Message to the browser when an
exception occur how can I do that.
I tested to use Respone.Write but that was not possible ?
[WebMethod]
public decimal HowMuchWillItCost(string productName, int howMany)
{
SqlConnection sqlConn = null;
try
{
ConnectionStringSettings cs =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"];
string connString = cs.ConnectionString;
sqlConn = new SqlConnection(connString);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = string.Format(@"select UnitPrice from Products
where productName = {0}", productName);
sqlCmd.Connection = sqlConn;
sqlConn.Open();
decimal price = (decimal)sqlCmd.ExecuteScalar();
return price * howMany;
}
catch (Exception ex)
{
return 1;
}
finally
{
if (sqlConn != null)
sqlConn.Close();
}
}
//Tony