Access conn.Open出现未指定的错误 .net的解决方法

conn.Open打开是有次数上限的

 

解决办法

编码过程中使用返回SqlDataReader类型函数来操作数据库时,何如关闭数据库连接
如:
        public static OleDbDataReader ExecuteReader(string strSQL)
        {
            OleDbConnection connection = new OleDbConnection(connectionString);
            OleDbCommand cmd = new OleDbCommand(strSQL, connection);
            try
            {
                connection.Open();
                 OleDbDataReader myReader = cmd.ExecuteReader( CommandBehavior.CloseConnection);//最重要  
                return myReader;
            }
            catch (System.Data.OleDb.OleDbException e)
            {
                throw new Exception(e.Message);
            }

  

你可能感兴趣的:(Access)