English 中文(简体)
在试图处理两个问题时,数据查询人已经出现公开错误
原标题:DataReader already open error when trying to run two queries

我有两点问,我需要把一个操作到一个连接的服务器上,另一个不喜欢。

    Dim InvestorLookup As String = "DECLARE @investor varchar(10), @linkedserver varchar(25), @sql varchar(1000) "
    InvestorLookup += "SELECT @investor =  " & investor & " , @linkedserver =  " & db & " , "
    InvestorLookup += "@sql =  SELECT * FROM OPENQUERY(  +@linkedserver +  ,   SELECT * FROM db WHERE investor =   + @investor +     )  EXEC(@sql)"
    Dim queryInvestorLookup  As SqlCommand = New SqlCommand(InvestorLookup , conn)

    Dim BondNoDR As SqlDataReader = queryInvestorLookup.ExecuteReader()

    Dim PasswordCheck As String = "DECLARE @investor varchar(10), @password varchar(20), @linkedserver varchar(25), @sql varchar(1000) "
    PasswordCheck += "SELECT @investor =  " + investor + " , @password =  " + password + " , @server =  " + db2 + " , "
    PasswordCheck += "@sql =  SELECT * FROM @server WHERE investor = @investor AND password =   + @password +      EXEC(@sql)"
    Dim queryPasswordCheck As SqlCommand = New SqlCommand(PasswordCheck, conn)

    Dim PasswordDR As SqlDataReader = queryPasswordCheck.ExecuteReader()

只要我能够告诉大家,两点问话都是一样的,但我有错误。

There is already an open DataReader associated with this Command which must be closed first.

是否有可能在两个不同的数据管理员中提出两个问题。 以后,我需要逐项参考数据,并从中选择数值。

最佳回答

缺席,不可能同时拥有两个SqlDataReader,同时分享同样的SqlConnection物体。 您在提一下第二(KryPasswordCheck)之前,应先结束第一(KryInvestorLookup)。

这一点从设计和业绩的角度来说是好的,因为建议是这样。 NET是,所有未管理的资源(如数据库接入)都尽可能晚开放,并尽早关闭。

另一种方式是,只有Sql2005和Sql2005年才能获得这种物质。

第三项解决办法是利用同一SqlDataReader发出两点询问,然后使用“后继结果”方法处理。

问题回答

如果你正在使用这种支持,你可以通过在你使用的连接线上添加多功能ResultSets=True,使MARS(Multipleactive Result Sets)成为可能。

否则,你就不必就同样的关系提供数据。 因此,你可以得出一个结果,把结果装在数据表上,然后取得另一个结果。 或者,你可以转而使用《国际船舶和船舶登记法》。

ADO.NET 多人Resut Sets





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签