-1
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "Data Source=.;Database = deptStore;Integrated Security = true;";
cnn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into Employee values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "','" + TextBox13.Text + "')";
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
Response.Write("Record Save");
cnn.Close();

But I am getting following Error:

SqlConnection cnn = new SqlConnection(); cnn.ConnectionString = "Data Source=.;Database = deptStore;Integrated Security = true;";

            cnn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "insert into Employee values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "','" + TextBox13.Text + "')";
            cmd.Connection = cnn;
            cmd.ExecuteNonQuery();
            Response.Write("Record Save");
            cnn.Close();

But iam getting following Error: SqlException was unhandled by user code

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Kindly help me to understand the error and rectify it.

user1716251
  • 135
  • 1
  • 1
  • 6
  • I fixed your subject to better reflect the question and cleaned up your question with some formatting. – Burhan Khalid Oct 21 '12 at 08:23
  • could be a certificate issue check this so post http://stackoverflow.com/questions/1884959/exception-on-sslstream-authenticateasclient-the-message-was-badly-formatted – Prabhu Murthy Oct 21 '12 at 08:27

1 Answers1

0

Make sure you have enabled TCP/IP in SQL Server Configuration Manager: Enable Network Access in SQL Server Configuration Manager

Also, Start the SQL Server Browser Service: Start and Stop the SQL Server Browser Service

giftcv
  • 1,670
  • 15
  • 23