-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();

但我收到以下错误:

SqlConnection cnn = new SqlConnection(); cnn.ConnectionString = "数据源 =.;数据库 = deptStore;集成安全 = 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();

但是我收到以下错误:用户代码未处理 SqlException

建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:命名管道提供者,错误:40 - 无法打开与 SQL Server 的连接)

请帮助我理解错误并纠正它。

4

1 回答 1

0

确保您已在 SQL Server 配置管理器中启用 TCP/IP:在 SQL Server 配置管理器中启用网络访问

另外,启动 SQL Server Browser 服务:启动和停止 SQL Server Browser 服务

于 2012-10-21T09:09:44.433 回答