读者关闭相关的东西. [英] Reader Close related thing.

查看:71
本文介绍了读者关闭相关的东西.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

public void test()
{
      MySqlDataReader oReader = myExecuteReader(selectQuery);
      
      oReader.Close();
 
}


public MySqlDataReader myExecuteReader(string SQL_STRING)
		{	
			//Function to Accept a SQL String and Return a Data Reader
			//Declare Objects
			MySqlConnection oCn = null;
			MySqlCommand oCmd = null;
			MySqlDataReader oRdr = null;

            try
            {
                //Open Connection
                oCn = new MySqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);
                oCn.Open();

                //Open the MySqlCommand object
                oCmd = new MySqlCommand(SQL_STRING, oCn);

                //Return the Data Reader to the callee
                oRdr = oCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
            }
			
			return oRdr;
					
		}	//End Function 




我的问题是,当我关闭oReader Reader时,它会关闭函数中存在的阅读器吗?

否则它将保持打开状态?

请提出

在此先感谢




My question is when i close the oReader Reader than is it will close the reader present inside the function???

or it will remains open???

Please suggest

Thanks in advance

推荐答案

否.
测试"方法中的oReader是一个完全独立的实例.
No.
The oReader inside the "test" method is a completely separate instance.


假定MySqlDataReader是一种引用类型,是的,在测试中关闭它会关闭myExecuteReader内部的一个,因为它是一个引用相同的MySqlDataReader. (如果MySqlDataReader是值类型,那么这将不是正确的,因为您将使用副本.)
Assuming MySqlDataReader is a reference type, yes closing it in test will close the one inside of myExecuteReader, because it''s a reference to the same MySqlDataReader. (If MySqlDataReader is a value type then this would not be true, as you would instead be working with a copy.)


如果您将其作为值类型传递,则不会关闭它,但您将其作为引用类型传递,则它将关闭.
if you have passed it as value type then it will not be closed, but you passed it as referenced type then it will closed.


这篇关于读者关闭相关的东西.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆