G
Guest
Hi all,
I haven't really used the TRY statement much, so am not sure when to use and
and how to use it just yet. Any general hints?
For example, when using it, should a create database statement fall within
the try statement or outside of it, when using the EL (Enterprise Library).
In examples online, not using EL, the create db stuff occurs before the try
statement.
This is how i have implemented it so far!
try
{
//Should this be here?????
Database Db = DatabaseFactory.CreateDatabase();
//create db command object for 'Login_ChangePassword' proc
DbCommand DbCommand =
Db.GetStoredProcCommand("Login_ChangePassword");
//add required parameters
Db.AddInParameter(DbCommand, "@Password", DbType.String,
newPassword);
Db.AddInParameter(DbCommand, "@Username", DbType.String,
username);
//execute command; populate local variable indicating rows
affected
RowsAffected = Db.ExecuteNonQuery(DbCommand);
}
catch (SqlException ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Log Only
Policy");
if (rethrow) throw;
}
Help Appreciated!
Cheers,
I haven't really used the TRY statement much, so am not sure when to use and
and how to use it just yet. Any general hints?
For example, when using it, should a create database statement fall within
the try statement or outside of it, when using the EL (Enterprise Library).
In examples online, not using EL, the create db stuff occurs before the try
statement.
This is how i have implemented it so far!
try
{
//Should this be here?????
Database Db = DatabaseFactory.CreateDatabase();
//create db command object for 'Login_ChangePassword' proc
DbCommand DbCommand =
Db.GetStoredProcCommand("Login_ChangePassword");
//add required parameters
Db.AddInParameter(DbCommand, "@Password", DbType.String,
newPassword);
Db.AddInParameter(DbCommand, "@Username", DbType.String,
username);
//execute command; populate local variable indicating rows
affected
RowsAffected = Db.ExecuteNonQuery(DbCommand);
}
catch (SqlException ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Log Only
Policy");
if (rethrow) throw;
}
Help Appreciated!
Cheers,