Saturday, August 22, 2009

Returning multiple refcursor in Oracle through enterprise library 4.1

I found this simple code snippet for how to retrieve multiple RefCursor values in Oracle through Enterprise Library 4.1

object[] parameters = new object[3];
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cw = db.GetStoredProcCommandWrapper("mypackage.mypackagename", parameters);
db.LoadDataSet(cw, ds, new string[] {"RefCur1", "RefCur2", "RefCur3"});

Thursday, August 20, 2009

Exception handling in Enterpirse Library 4.1

After goggling lot very patiently,I find something all irrelevant to my task.
Finally i corrected by watching carefully on my system thrown exceptions.

Add this below line between ConfigSection of tag.

section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" /

Paste this line somewhere but between configuration tag
exceptionHandling
exceptionPolicies
add name="Global Policy"
exceptionTypes
add name="Exception"
type="System.Exception,
mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089"
postHandlingAction="None"

/add
/exceptionTypes
/add
/exceptionPolicies
/exceptionHandling

My source code for catching the exception is

try
{
int a = 0;
int b = 1;
int result = b / a;
Response.Write(result.ToString());

}
catch (System.Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Global Policy");
Response.Write(rethrow.ToString());

}

Output is "False".So I am strongly believe exceptions were caught by enterprise library : )-

Monday, August 17, 2009

Record retreiving C# using OracleProcedure

Oracle Proc:

create or replace procedure returnAllRecords(cur_allrec out t_cursor)
is
begin
open cur_allrec for SELECT * from Students;
end returnAllRecords


on Button click event write this below code:



OracleConnection Conn = new OracleConnection("Data Source=ORCL; User ID=scott; Password=tiger")
OracleCommand Cmd = new OracleCommand();
Cmd.Connection = Conn;
Cmd.CommandText = "returnAllRecords";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("cur_allrec", OracleType.Cursor).Direction = ParameterDirection.Output;
try

{

Conn.Open();

OracleDataReader Reader = Cmd.ExecuteReader();


}

catch (Exception ex)

{

Response.Write(ex.ToString();

}


Conn.Close();

Wednesday, August 12, 2009

Operation Contract's properties

OperationContract Properties
Action
The Action property specifies the action that uniquely identifies this operation. WCF dispatches request messages to methods based on their action.
AsyncPattern
The AsyncPattern property indicates that the operation is implemented or can be called asynchronously using a Begin/End method pair.
HasProtectionLevel
The HasProtectionLevel property indicates whether the ProtectionLevel property has been explicitly set.
IsOneWay
The IsOneWay property indicates that the operation only consists of a single input message. The operation has no associated output message.
IsInitiating
The IsInitiating property specifies whether this operation can be the initial operation in a session.
IsTerminating
The IsTerminating property specifies whether WCF attempts to terminate the current session after the operation completes.
ProtectionLevel
The ProtectionLevel property specifies the message-level security that an operation requires at run time.
ReplyAction
The ReplyAction property specifies the action of the reply message for the operation.

Tuesday, August 04, 2009

Opening popup window in ASP.NET

Opening popup window in ASP.NET is quite simple,but you need to very concern about concatenation on javascript and as well as ASP.NET concatenation.

I spent more time on this silly issue,atlast i rectified.
Here i attach my querystring and its value from the selected dropdown list control.

string result = DropDownList1.SelectedValue.ToString();
string script = "";
Page.RegisterStartupScript("myScript", script);

Working with access database in C#

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
OleDbConnection Con = null;
OleDbCommand cmd = null;
OleDbDataReader reader;
protected void Page_Load(object sender, EventArgs e)
{


}
protected void btnUpdate_Click(object sender, EventArgs e)
{
Con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Server.MapPath("iTrack.mdb"));
Con.Open();
string t_date = txtDate.Text;
string t_location = txtLocation.Text;
string t_descrip = txtNotes.Text;
string t_time = txtTime.Text;
cmd = new OleDbCommand("INSERT INTO bills (Transaction_date,Location,Transaction_Description,TTime)values('" + t_date + "','" + t_location + "','" + t_descrip + "','" + t_time + "')", Con);

cmd.ExecuteNonQuery();

Response.Write("Added");
cmd.Dispose();
Con.Close();
cmd = null;
Con = null;

}


protected void btnRetrieve_Click1(object sender, EventArgs e)
{
try
{
Con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Server.MapPath("iTrack.mdb"));
Con.Open();
cmd = new OleDbCommand("SELECT * from Bills where Awb='"+DropDownList1.SelectedValue.ToString()+"'", Con);
reader = cmd.ExecuteReader();
while (reader.Read())
{
txtDate.Text = reader["Transaction_date"].ToString();
txtLocation.Text = reader["Location"].ToString();
txtNotes.Text = reader["Transaction_Description"].ToString();
txtTime.Text = reader["TTime"].ToString();
plDetails.Visible = true;
}
}
catch (Exception exception)
{
Response.Write("Exception Message " + exception.Message.ToString());
}

finally
{
cmd.Dispose();
cmd = null;
Con.Close();
Con = null;
}

}
}