.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
ASPEvil
Jean Paul
SP
satyapriyanayak
Ashutosh Jha
Post New Web Links

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

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net
 

when i insert record

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

help me.

SqlConnection conn = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=StudentDetails;Integrated Security=True");

SqlCommand cmd2 = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();

if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

cmd2 = new SqlCommand("Select * from UserInfo where Standard", conn);
            }
            
            SqlDataReader dr1 = cmd2.ExecuteReader();
            string stu, par,std,sec,roll;
            par = "";
            stu = "";
            std = "";


View Complete Post


More Related Resource Links

Why do I get: There is already an open DataReader associated with this Command which must be closed

  

Hi!

I create a Form and show it:

            JelentesForm jf = new JelentesForm(Globals.DC, (int)row.Cells["Jelentes_ID"].Value);
            jf.StartPosition = FormStartPosition.CenterParent;
            jf.ShowDialog();

The form gets the DataContext (DC) and the ID of row in a table to work with.

In the constructor the form reads the row, then validates it:

            var jel = from j in context.JELENTES where j.Jelentes_ID == Jelentes_ID select j;
            jelentes = jel.Single();
...

            validateAll();

The validating means calling the same stored procedure for the fields to check them. The stored procedure reads data from other tables for checking.

When I open the form first time it is all right. When I close the form (without any action) and open it second time I get the error above in the validateAll() on the first call of stored procedure.

I tried to move the validateAll() from constructor into form_Shown event, then tried to move it into a

There is already an open DataReader associated with this Command needs to be Closed

  

Hi,

Hope this subject seems to be familiar in search. I need this subject to be taken for a discussion to get the right solution for me.


My scenario:

I am using  a web service which access the sql server database to provide an XML output. this part is working fine. I am using a SqlDataAdapter and DataTable with Fill method to get the data.

Problem:

When more than one person access this web service at the same time i get the error message which is given in the subject line.

I understand the problem is because of the sql connection which is still open by the first user. If the first user completes his operation before the second users request then both the user receives the correct response.

My Solution:

What i did was i initiated 10 connection strings and will check which connection string is closed and i have used this connection for the second persons request if they both access at the same time.

My Question:

I know this is not the best solution. So i want to take this topic to be discussed to get a right solution. I am in need of some idea from the experts in this forum to resolve my issue.

 

Thanks & Regards

Karthikeyan S

 

Patterns in Practice: The Open Closed Principle

  

Extending an existing codebase can be as productive and frustration-free as writing all new code when you employ the Open Closed Principle. We'll show you how.

Jeremy Miller

MSDN Magazine June 2008


Open a Command Prompt of Remote Computer

  
Hi All, I need to open a Command prompt (cmd.exe) of a Remote server computer and Run a Command from my asp.net web application (C# laungauge).  I have progressed till opening a command prompt of the webserver where the website is hosted. My code is:System.Diagnostics.ProcessStartInfo psi = new ProcessStartInfo(); psi.WorkingDirectory = "C:\\WINDOWS\\system32"; psi.FileName = "cmd.exe"; Process p = Process.Start(psi); System.Threading.Thread.Sleep(5000); I have achived this using the VB script. The code is:wshShell.run("c:\scripts\uptime\psexec.exe \\nawinapp627 -u domainname\userid -p password cmd.exe") WScript.Sleep 5000 In the above code psexec.exe is software used to access remote computers. nawinapp627 = Remote server Please help me to achieve above using C#. Advance thanks..

ReportBuilder 2.0: open server report via command line?

  
Hello,is it possible to launch ReportBuilder 2.0 and pass the server report to open via command line?Searching the forums I have found this blog-entry (Launching Report Builder from the command line), but I think it is for ReportBuilder 1.0, because SQL Server 2005 is mentioned. I have tried it anyway, but ReportBuilder 2.0 just starts with an empty report.If I specify a rdl-file from the local file system the report will open fine:MSReportBuilder.exe d:\temp\samplereport.rdlthanks in advance and best regards,Gerald

DataReader.Read closed premeturely

  
HiI noticed a very strange thing. I was debugging the following code, and thus had put the breakpoint at line: using (IDataReader dataReader = db.ExecuteReader(dbCommand)). dataReader was getting populated, but after a halt of lets say 30 seconds, dataReader was emptied, while I was debugging.So when control went to dataReader.Read(), i got error: "Invalid attempt to call FieldCount when reader is closed".But if i execute the function at one go, without halting at dataReader line (without breakpoint), it works alright.My question is what is triggering the dataReader to close ?Its a legacy code, and have worked fine. Database db;db = DatabaseFactory.CreateDatabase(); db.AddInParameter(dbCommand, "ID", DbType.String, ID);                 do                 {                     try                     {                         using (IDataReader dataReader = db.ExecuteReader(dbCommand))                         {                             while (dataR

ExecuteReader requires an open and available Connection. The connection's current state is closed.

  

I am accessing SQL2005 with C# code using  OleDbConnection.

 

A try and catch block catches the following error once a while between the Open() and Close() of the connection:

ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.

 

I do not even have any idea where to start to debug this.  The ExecuteNonQuery() runs a delete SQL query. It works 99.9% of the time. I do not see anything wrong when this error happens. 

 

Any hint would be greatly appreciated.

 

 


Closed form designer window in VS 2008, now cannot open again

  

 

I closed the Form1.Designer.vb tab in VS 2008.  If I click on Form1.vb in the Solution Explorer the View Designer button does not appear.  How can I open the designer window again?

Users with permissions cant open or edit form - "The form has been closed"

  

Dear All,

I am facing this unique problem. Some users in my company's SharePoint portal network despite user permissions, cant open their previous forms or add a new form. Just for testing I also tried giving one of the users full rights, but the problem persists. I am using infopath web based forms.

Following is the error when the user opens up a form:

" Form has been closed"

Upon checking the SharePoint error logs. I found following error message

The form template failed to load. (User: Litware\max.steve, Form Name: Expense, IP": , Request: http://portal/_layouts/FormServer.aspx?XsnLocation=http://portal/hr/Expense/Forms/template.xsn&SaveLocation=http://portal/hr/Expense&Source=http://port

How To Open Fancy Tooltip from GridView

  
This article will show How To Open show Fancy Tooltip in GridView.

Row command working on all rows not selected one?

  

Hi,

I have this code that hides a column in a gridview.  (The column houses another nested gridview).


    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Select" Then
            If GridView1.Columns(0).Visible = False Then
                GridView1.Columns(0).Visible = True
            Else
                GridView1.Columns(0).Visible = False
            End If
        End If
    End Sub


The trouble is that if I click the select link on one row that action to hide is carried out on all rows.  How can I set this up so that it only hides the row that is selected?


Thanks.


Open ModalPopup dialog on page load

  

Is there a way to make a modal popup panel active on page load so that the user can't do anything until they deal with the popup dialog?


Print command

  

 

Is there a way of setting up a print area for a part of my webpage, I only want to print a certain part of the page, when I select print at the moment it will print the whole page and the layout is rubbish!!
 
Thanks
 
Richard

command object error

  

Could someone please tell me what is wrong with my syntax here?  I'd be much appreciative.

 

objCmd = New SQLCommand("SELECT CASE WHEN objDR('Item') = 'Enter Bill of Lading' then enterbol " _  

& "WHEN objDR('Item') = 'Bill of Lading History' THEN bolhistory " _  

& "WHEN objDR('Item') = 'Request Transfer' or objDR('Item') = 'View Transfer in Progress' THEN transfers " _  

& "END  from plantGroups where plantgroupid=@plantgroupid", objConn)


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend