i am working on asp.net +C#
my problem is that if due to any reason net connection is failed while user was entering his details.and as he clicked submit ........so how it should be handle that what ever user has entered must be saved afterward as net connection is regained
automatically!
how its hud be done automatically.
Loading
Vijaya KadiyalaPosted Apr 8, 2009, 4:24 PM
Hi Deepak,
"my problem is that if due to any reason net connection is failed while user was entering his details.and as he clicked submit "
Your question is at the front-end side i.e entering some detailes in the form and use hits the sunit buton and if DB connection is not available!!! You want to retain the same values in the front-end form!!!
Thanks -- Vijaya Kadiyala
www.dotnetvj.com
deepika agarwalPosted Apr 6, 2009, 3:06 AM
thanku Niradhip sir and abhishek sir i will try with abv code then reply you.
thankyou!!
Abhishek hPosted Apr 6, 2009, 2:59 AM
Niradhip ChakrabortyPosted Apr 6, 2009, 2:19 AM
If the database connection goes down, say after entering into two table. What you can do is rollback the transaction. Because you don’t know how long the connection will be down. You can show a message to user as "Try after some time."
Please check below the rollback code.
private void updateData()
{
SqlConnection sqlCon = null;
sqlCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
SqlCommand sqlCmd = new SqlCommand();
SqlDataAdapter adpData = null;
SqlDataReader sdrData = null;
DataSet dstData = new DataSet();
SqlTransaction myTrans = null;
try
{
sqlCon.Open();
myTrans = sqlCon.BeginTransaction();
sqlCmd.Connection = sqlCon;
sqlCmd.Transaction = myTrans;
// ===================================
All your insert statement code will come here
//=======================================
myTrans.Commit();
myTrans = null;
sqlCon.Close();
sqlCon = null;
sqlCmd = null;
}
catch (Exception ex)
{
if (myTrans != null)
{
try
{
myTrans.Rollback();
}
catch { }
}
if (sqlCon != null)
{
if (sqlCon.State == ConnectionState.Open)
{
sqlCon.Close();
}
sqlCon = null;
}
if (sqlCmd != null)
{
sqlCmd = null;
}
}
finally
{
}
}