-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 = 新しい 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 was unhandled by user code

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 に答える