Click here to Skip to main content
14,699,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam using Ado.net

the code algorithm is as follows
SqlConnection SelectConnection= new SqlConnection(connectionstring);

sqlConnection Updateconnection = new Sqlconnection(connectionstring);

Sqlcommand Updatecommand =  new SqlCommand();
updateCommand.Connectoin= UpdateConnection;

SqlCommand Selectcommand= new SqlCommand("Select * From A " + ,Selectconnection);
SqlDataReader reader = Selectcommand.ExecuteReader();

while(Reader.read())
{
  updateCommand.CommandText="Update A set Column1 =" +  Guid.NewGuid();
  updateCommand.ExecuteNonQuery()
}

if table A Has more than 2000 record i got the following exception
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

what should i do? please help me

i tried the solution that is putting command.Timeout=90 in connectionstring
but it doesn't work
Posted
Updated 30-Nov-14 3:44am
v4
Comments
George Jonsson 30-Nov-14 8:10am
   
Is this your actual code?
Seems like you don't use the result from the select statement for anything more than to get the number of rows in the database.
Tomas Takac 30-Nov-14 8:19am
   
The code doesn't make much sense. For each row in A you update all rows in A setting Column1. There is something you are not showing. Update your question with a more complete and meaningful sample.
oula alsheikh 30-Nov-14 8:46am
   
you are right it is not the actual code because actual code is complicated
i put the algorithm of the code in a way of code
George Jonsson 30-Nov-14 9:44am
   
When you post code, make sure it is not full of errors like the code above.
For example, sqlConnection should be SqlConnection.
It gives people the impression that you don't even check the simplest of things.

1 solution

As you don't show much of your code, is is difficult to give any specific solution.
You code try to divide your code into two different parts, Select and Update.
At least it will be easier to find out which connection it is that throws the exception.
Also consider not to use SELECT * as it will give give you more data that you might need. In this case you might only need the primary key of the table, but it is difficult to say with so very little information.
#region Select
DataTable dtResult = new DataTable();
using (SqlConnection SelectConnection = new SqlConnection(connectionString))
{
    SqlDataAdapter da = new SqlDataAdapter("Select * From A", SelectConnection);
    da.Fill(dtResult);
    da.Dispose();
}
#endregion

#region Update
using (SqlConnection UpdateConnection = new SqlConnection(connectionString))
{

    SqlCommand updateCommand = new SqlCommand();
    updateCommand.Connection = UpdateConnection;


    foreach (DataRow dr in dtResult.Rows)
    {
        // Whatever code you have here
    }
}
#endregion
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900