未处理的“System.Data.SqlClient.SqlException”类型的错误出现在 System.Data.dll 中。而且还找不到存储过程
未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 System.Data.dll 中。而且还找不到存储过程
请帮帮我,这个问题困扰着我,让我头疼,谢谢了
下面的是我的代码:
private void btnOK_Click(object sender, EventArgs e)
{
if (this.textName.Text == "")
{
MessageBox.Show("用户名不能为空");
}
else
{
SqlConnection SqlCon = new SqlConnection(@"server=.;database=master;Integrated Security=True");//连接数据库
SqlCon.Open();//打开连接
SqlCommand Cmd = new SqlCommand("StoredProcedure2", SqlCon);//调用存储过程
Cmd.CommandType = CommandType.StoredProcedure; //设置解释命令为存储过程
SqlParameter p = Cmd.Parameters.Add("name", SqlDbType.VarChar, 50);//设置存储过程需要的参数"@N"
p.Value = this.textName.Text;//给"@N"赋值
p = Cmd.Parameters.Add("passwd", SqlDbType.VarChar, 50);//设置存储过程需要的参数"@P"
p.Value = this.textPwd.Text; //给"@P"赋值
SqlDataReader Reader = Cmd.ExecuteReader();//执行产寻
Reader.Read();
if (Reader.HasRows)//判断是否有查询到对象的数据
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Final");
}
SqlCon.Close();//关闭连接
}
------解决方案--------------------
首先需要明确的是,你的SQLException的具体情况,也就是bug具体内容是什么
另外,建议sqlConnection使用数据库帐号密码的方式来连接
还有就是数据库的操作应该是
try{
conn.open();
.....
}catch(Exception ex)
{
}
finally
{
if(conn.ConnectionState!=ConnectionState.Closed)
{
conn.close();
}
}
确保conn在任何状态下的关闭。
------解决方案--------------------
可能是连接串问题,
"server=.;database=master;uid=sa;pwd=sa;"
请帮帮我,这个问题困扰着我,让我头疼,谢谢了
下面的是我的代码:
private void btnOK_Click(object sender, EventArgs e)
{
if (this.textName.Text == "")
{
MessageBox.Show("用户名不能为空");
}
else
{
SqlConnection SqlCon = new SqlConnection(@"server=.;database=master;Integrated Security=True");//连接数据库
SqlCon.Open();//打开连接
SqlCommand Cmd = new SqlCommand("StoredProcedure2", SqlCon);//调用存储过程
Cmd.CommandType = CommandType.StoredProcedure; //设置解释命令为存储过程
SqlParameter p = Cmd.Parameters.Add("name", SqlDbType.VarChar, 50);//设置存储过程需要的参数"@N"
p.Value = this.textName.Text;//给"@N"赋值
p = Cmd.Parameters.Add("passwd", SqlDbType.VarChar, 50);//设置存储过程需要的参数"@P"
p.Value = this.textPwd.Text; //给"@P"赋值
SqlDataReader Reader = Cmd.ExecuteReader();//执行产寻
Reader.Read();
if (Reader.HasRows)//判断是否有查询到对象的数据
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Final");
}
SqlCon.Close();//关闭连接
}
C#
------解决方案--------------------
首先需要明确的是,你的SQLException的具体情况,也就是bug具体内容是什么
另外,建议sqlConnection使用数据库帐号密码的方式来连接
还有就是数据库的操作应该是
try{
conn.open();
.....
}catch(Exception ex)
{
}
finally
{
if(conn.ConnectionState!=ConnectionState.Closed)
{
conn.close();
}
}
确保conn在任何状态下的关闭。
------解决方案--------------------
可能是连接串问题,
"server=.;database=master;uid=sa;pwd=sa;"