private SqlConnection sqlCon=null;//一般连接
private SqlConnection sqlConForTran=null;//事务连接
以下是我定义的方法
public void BeginTrans()
{
sqlConForTran=new SqlConnection(Sqlstrconn);
if(sqlConForTran.State!=ConnectionState.Open)sqlConForTran.Open();
sqlTran=sqlConForTran.BeginTransaction();
} public void CommitTrans()
{
sqlTran.Commit();
sqlTran.Dispose();
sqlConForTran.Close();
} public void RollbackTrans()
{
sqlTran.Rollback();
sqlTran.Dispose();
sqlConForTran.Close();
} public DataTable ExecuteToTable(string Sql)
{
//填充DataTable
SqlDataAdapter MyDataAdapter;
MyDataAdapter=new SqlDataAdapter(Sql, sqlCon);
DataSet  MyDataSet=new DataSet();
string tbName=BuildTable();
try
{
MyDataAdapter.Fill(MyDataSet,tbName);
}
catch(Exception e)
{
eMsg=e.Message;
}
return MyDataSet.Tables[tbName];
}当我如此调用时
BeginTrans();ExecuteToTable(sql)时,ExecuteToTable中的连接超时
请问这是什么原因,如果解决

解决方案 »

  1.   

    帮你顶url地址重写以后为什么除了百度别的搜索引擎都搜索不到内页呢? 
    http://community.csdn.net/Expert/topic/4545/4545068.xml?temp=.5926172
      

  2.   

    MyDataAdapter=new SqlDataAdapter(Sql, sqlCon);
    sqlCon不是sqlConForTran??
      

  3.   

    是中间用到ExecuteNonQuery方法 public bool ExectueNo(string Sql)
    {
    //执行sql查询
    bool succ;
    SqlCommand MyCommand=null;
    if(sqlTran==null)
    {
    MyCommand=new SqlCommand(Sql, sqlCon);
    }
    else
    {
    MyCommand=new SqlCommand(Sql, sqlConForTran);
    }
    try
    {
    if(sqlTran!=null)MyCommand.Transaction=sqlTran;//使用事务
    succ=(bool)(MyCommand.ExecuteNonQuery()!=0);
    MyCommand.Dispose();
    }
    catch(Exception e)
    {
    eMsg=e.Message;
    succ=false;
    }
    return succ;
    }