日期:2014-05-19  浏览次数:20820 次

数据库连接调试与非调试出现的错误,什么原因?
我初学.net现在试做一个数据库操作,代理如下:
string   StrConn= "server=PCServer;database=DB;uid=sa;pwd=sa ";
string   SQL   =   "select   top   1   UserName   from   Member ";
string   TmpStr= " ";

SqlConnection   Conns   =   new   System.Data.SqlClient.SqlConnection(StrConn);
Conns.Open();

SqlCommand   cmd   =   new   SqlCommand(SQL,Conns);

SqlDataReader   DataRow   =   cmd.ExecuteReader(CommandBehavior.SingleRow);

while   (DataRow.Read()){
    TmpStr   =DataRow.GetString(0);
    DataRow.NextResult();
}
DataRow.Close();
Conns.Close();
textBox1.Text   =   TmpStr;
其它Conns.Open在按F5(调试)下执行报出错误:
未处理的“System.NullReferenceException”类型的异常出现在   system.data.dll   中。
其他信息:   未将对象引用设置到对象的实例
如果按CTRL+F5(不调试)运行正常.为什么呢?

------解决方案--------------------
Clean Solution 后再试一下,或者把Debug里删除掉再Debug
------解决方案--------------------
string StrConn=@ "server=PCServer;database=DB;uid=sa;pwd=sa ";

这样试下

楼主跟踪调试,看问题出在哪里