SQL Error - Saving gridview data to SQL database table

Hi,

I am trying to save gridview data to a database table by means of the following code attached.  I tested the query, and it works fine.  I am getting an error at line:

"cmd.ExecuteNonQuery();"

Error:  A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The handle is invalid.)

protected void Save_Click(object sender, ImageClickEventArgs e)
        {
            foreach (GridViewRow gvr in GridView2.Rows)  
            {
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = "ConnectionString";

                string SqlString = "insert into [Applied_DailyHrs](Name,Employee_ID, DailyHrsDate, Rules SRay_ID, ProductLine, Calc_first_clock, Calc_last_clock, Calc_work_Start, Calc_work_end, Worked_Hrs, Extra_Before, Extra_during, Extra_after, NormalDay) values ("+ "'test2'" + "," + gvr.Cells[0].Text + "," + "'" + gvr.Cells[5].Text  + "' ," + gvr.Cells[1].Text + "," + gvr.Cells[2].Text + "," + "2" + "," + "'" + gvr.Cells[6].Text + "' ," + "'" + gvr.Cells[7].Text + "' ," + "'" + gvr.Cells[8].Text + "' ," + "'" + gvr.Cells[9].Text + "' ," + "'" + gvr.Cells[10].Text + "' ," + "'" + gvr.Cells[11].Text + "' ," +
"'" + gvr.Cells[12].Text + "' ," + "'" + gvr.Cells[13].Text + "' ," + "'" + gvr.Cells[3].Text + "'" + ")"; 

SqlCommand cmd = new SqlCommand(SqlString, Conn);
Conn.Open();
cmd.ExecuteNonQuery();
Conn.Close();
    }

}

Open in new window

NerishaBAsked:
Who is Participating?
 
kamindaConnect With a Mentor Commented:
It looks like there are quit a few reasons for this error.

It also can be random network issue. Can you please try and do a reboot and see whether it helps.

Also check this thread http://www.bigresource.com/Tracker/Track-ms_sql-zF9EpGS8/ Which says some issue with .Net connection pooling
0
 
kamindaCommented:
You have to use a proper connection string in this line

Conn.ConnectionString = "ConnectionString";

0
 
kamindaCommented:
If it hidden only in this sample, please verify your connection string is correct. This is a connectivity issue you are having with SQL Server.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Alpesh PatelAssistant ConsultantCommented:
refer : connectionstring.com
0
 
NerishaBAuthor Commented:
My connectionstring is hidden for security purposes.  I dont know if it is a connectivity issue, as it retrieves the correct data, It just does not save the data to the DB.
0
 
NerishaBAuthor Commented:
Think you were right, I restarted and it works fine now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.