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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Alpesh PatelAssistant ConsultantCommented:
refer : connectionstring.com
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

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
kamindaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NerishaBAuthor Commented:
Think you were right, I restarted and it works fine now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.