저장 프로 시저를 통해 데이터베이스에 값을 삽입하려면 다음 함수를 사용합니다. 그러나 예외는 sqlConnection.Open()
입니다. 어떻게 해결합니까?SQL Server 2005의 저장 프로 시저
try
{
string dbConnectionString = "something";
SqlConnection sqlConnection = new SqlConnection(dbConnectionString);
SqlCommand command = new SqlCommand("sp_Test", sqlConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@id ", SqlDbType.Int).Value = TextBox1.Text;
command.Parameters.AddWithValue("@FullName", SqlDbType.VarChar).Value = TextBox2.Text;
sqlConnection.Open();
command.ExecuteNonQuery();
sqlConnection.Close();
}
catch (SqlException ex)
{
Console.WriteLine("SQL Error" + ex.Message.ToString());
}
당신은 예외가 무엇인지 설명하지 않았습니다. – Dai
어떤 예외가 있습니까? 실제 연결 문자열이 올바른지 (정확한 서버, 올바른 로그인 자격 증명) 확신합니까? – freefaller
프로그래밍 측면 노트 : 비싼 리소스의 범위를 지정하려면'using' 문을 사용하십시오. – bluevector