Problem with continue in While Loop within Try/Catch in C# (2.0)

Posted by csharpnoob on Stack Overflow See other posts from Stack Overflow or by csharpnoob
Published on 2010-05-19T22:25:52Z Indexed on 2010/05/19 22:30 UTC
Read the original article Hit count: 234

Filed under:
|
|

Hi, when i try to use in my ASPX Webpage in the Code Behind this

    try{                    
    while()
    {
        ...
        db.Open();
                readDataMoney = new OleDbCommand("SELECT * FROM Customer WHERE card = '" + customer.card + "';", db).ExecuteReader();
                while (readDataMoney.Read())
                {
                    try
                    {
                        if (!readDataMoney.IsDBNull(readDataMoney.GetOrdinal("Credit")))
                        {
                            customer.credit = Convert.ToDouble(readDataMoney[readDataMoney.GetOrdinal("Credit")]);
                        }
                        if (!readDataMoney.IsDBNull(readDataMoney.GetOrdinal("Bonus")))
                        {
                            customer.bonus = Convert.ToDouble(readDataMoney[readDataMoney.GetOrdinal("Bonus")]);
                        }
                    }
                    catch (Exception ex)
                    {
                        Connector.writeLog("Money: " + ex.StackTrace + "" + ex.Message + "" + ex.Source);
                        customer.credit = 0.0;
                        customer.credit = 0.0;
                        continue;
                    }
                    finally
                    {
                    }
                }
                readDataMoney.Close();
                vsiDB.Close();
            ...
     }
}catch
{
     continue;
}

The whole page hangs if there is a problem when the read from db isn't working. I tried to check for !isNull, but same problem. I have a lots of differend MDB Files to process, which are readonly (can't repair/compact) and some or others not. Same Design/Layout of Tables. With good old ASP Classic 3.0 all of them are processing with the "On Resume Next". I know I know. But that's how it is. Can't change the source. So the basic question:

So is there any way to tell .NET to continue the loop whatever happens within the try loop if there is any exception?

After a lots of wating time i get this exceptions:

    at System.Data.Common.UnsafeNativeMethods.IDBInitializeInitialize.Invoke(IntPtr pThis)
   at System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString constr, SessionWrapper& sessionWrapper)   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()
   at GetCustomer(String card)Thread was being aborted.System.Data

and

System.Runtime.InteropServices.Marshal.ReadInt16(IntPtr ptr, Int32 ofs) 
System.Data.ProviderBase.DbBuffer.ReadInt16(Int32 offset) 
System.Data.OleDb.ColumnBinding.Value_I2() 
System.Data.OleDb.ColumnBinding.Value() 
System.Data.OleDb.OleDbDataReader.GetValue(Int32 ordinal) 
System.Data.OleDb.OleDbDataReader.get_Item(Int32 index) 
Thread was terminated.mscorlib 

Thanks for any help.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#2.0