码迷,mamicode.com
首页 > 其他好文 > 详细

ServerVersion异常,无效操作。连接被关闭。解决方案

时间:2014-08-21 19:10:44      阅读:584      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   strong   ar   问题   

【版权声明:本文为特维博客原创,未经准许谢绝转载。如需转载,请务必在转载时注明本博客地址。】

问题在于:State Closed System.Data.ConnectionState
连接没有open().
在try中加入
if (oleDbConnection1.State != ConnectionState.Open)
    oleDbConnection1.Open();
加上
finally
{
    if (oleDbConnection1.State != ConnectionState.Close)
    {
        oleDbConnection1.Close();
    }
}

 

详见http://bbs.csdn.net/topics/90347542

 

 
  1. /// <summary>  
  2.         /// 添加实体  
  3.         /// </summary>  
  4.         /// <param name="sysCompany"></param>  
  5.         /// <param name="sysUser"></param>  
  6.         public bool InsertEntities(TSysCompany sysCompany, TSysUser sysUser)  
  7.         {  
  8.             using (teaCRMDBContext db = new teaCRMDBContext())  
  9.             {  
  10.                 if (db.Connection.State != ConnectionState.Open)  
  11.                 {  
  12.                     db.Connection.Open();  
  13.                 }  
  14.                 var tran = db.Connection.BeginTransaction();  
  15.                 try 
  16.                 {  
  17.                     db.TSysCompanies.Insert(sysCompany);  
  18.                     db.TSysUsers.Insert(sysUser);  
  19.                     tran.Commit();  
  20.                     return true;  
  21.                 }  
  22.                 catch (Exception ex)  
  23.                 {  
  24.                     tran.Rollback();  
  25.                     throw new Exception(ex.Message);  
  26.                     return false;  
  27.                       
  28.                 }  
  29.                 finally 
  30.                 {  
  31.                     if (db.Connection.State != ConnectionState.Closed)  
  32.                     {  
  33.                         db.Connection.Close();  
  34.                     }  
  35.                 }  
  36.             }  
  37.         } 

ServerVersion异常,无效操作。连接被关闭。解决方案,布布扣,bubuko.com

ServerVersion异常,无效操作。连接被关闭。解决方案

标签:style   http   color   os   io   strong   ar   问题   

原文地址:http://www.cnblogs.com/tangyouwei/p/3927740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!