我的数据库是Syabse11,我使用的是ODBC连接方式,以前是在VS2003下开发的,没有任何异常,项目迁移到VS2005后,发现新开发的窗体都一个问题,就是窗体最大化过之后,再触发窗体的某个数据库操作函数就出现错误,而且还是需要发送错误报告的那种提示框(也就是说程序的try catch 根本不能捕捉到错误)。函数体如下:
private void btn_Query_Click(object sender, System.EventArgs e)
{
ds = db.SelectDataBase("exec CoinTradeCount '"+this.startDate.Value.ToString("yyyyMMddd")+"','"+this.endDate.Value.ToString("yyyyMMddd")+"'",this.table_name);
if(ds!=null)
{
this.dataGrid1.DataSource = ds.Tables[table_name];
}
else
{
CommonUtil.ShowError(this,Constant.NO_DATASET);
         }
}错误栈:  
System.Data.Odbc.OdbcException
   在 System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
   在 System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
   在 System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   在 System.Data.Odbc.OdbcConnection.Open()
   在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
   在 waihui.LinkDataBase.SelectDataBase(String tempStrSQL, String tempTableName)
望大家指教!

解决方案 »

  1.   

    如果是btn_Query_Click事件中的代码触发的,单步调试进行查看,就你目前的信息来说,好像是SelectDataBase这个函数有问题,进入内部进行查看。
      

  2.   

    SelectDataBase函数代码在这里,问题就是里面的try catch根本捕捉不到错误,单步执行到this.da.Fill(ds, tempTableName);就直接跳出一个框,告诉你某某程序发生异常,要不要发送错误报告,感觉就象底层代码出错一样public DataSet SelectDataBase(string tempStrSQL,string tempTableName)

    this.strSQL = tempStrSQL;
             try
             {
                    this.da = new OdbcDataAdapter(this.strSQL, this.myConnection);                if (this.ds != null && this.ds.Tables.Count > 0 && this.ds.Tables[tempTableName] != null)
                    {
                        this.ds.Tables[tempTableName].Clear();
                     }
                    this.da.Fill(ds, tempTableName);
                    return this.ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
              }
              catch (Exception ex)
              {
                    logUtil.WriteError(ex, this.GetType(), "SelectDataBase出错");
                    return null;
              }
              finally
              {
                 this.da.Dispose();
              }

    }
      

  3.   

    查询数据库失败和窗体最大化会有关系?
    没这么妖吧你可以做一个测试,新建一个工程,放一个窗体,只把查询数据库的代码移过来,输出就简单的在一个Listbox里面输出纪录。看看窗体最大化,会不会对查询数据库造成影响。