用.net写的注册程序,运行是好的,可就是提交信息时说数据库不存在或访问被拒绝,具体错误是SQL  Server  不存在或访问被拒绝。    
说明:  执行当前  Web  请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。    
 
异常详细信息:  System.Data.SqlClient.SqlException:  SQL  Server  不存在或访问被拒绝。  
 
源错误:    
 
 
行  72:      SqlConnection  Conn=new  SqlConnection(connstr);  
行  73:      SqlCommand  mycommand=new  SqlCommand(strsql,Conn);  
行  74:      Conn.Open();                //错误  
行  75:      int  flag=(int)mycommand.ExecuteScalar();  
行  76:      Conn.Close();  
   
源程序是  
private  void  BT_submit_Click(object  sender,  System.EventArgs  e)  
   {  
string  connstr="server=localhost;database=aspnet;uid=sa;pwd=";  
string  strsql="select  count(*)from  UserInfo  where  UserID  like'"+TB_UserName.Text+"'";  
SqlConnection  Conn=new  SqlConnection(connstr);  
SqlCommand  mycommand=new  SqlCommand(strsql,Conn);  
Conn.Open();     
int  flag=(int)mycommand.ExecuteScalar();  
Conn.Close();  
if(flag==0)  
{  
       string  WebSite;  
       WebSite=Request.UserHostAddress.ToString();  
       string  selectstr="insert  into  UserInfo(UserID,Pwd,Sex,Email,Website,RegTime)values('"+TB_UserName.Text+"','"+TB_Pwd.Text+"','"+RBL_Sex.SelectedItem.Value+"','"+TB_Email.Text+"','"+WebSite+"',getdate())";  
     SqlCommand  addcommand=new  SqlCommand(selectstr,Conn);  
     Conn.Open();     ///出错  
     addcommand.ExecuteNonQuery  ();  
     Conn.Close();  
     Session["username"]=TB_UserName.Text;  
     Session["Sex"]=RBL_Sex.SelectedItem.Value;  
     Label7.Text="注册成功,请先登录!";  
}  
else    
{  
     Label7.Text="对不起,该用户名已经存在,请选择其他用户名!";  
     TB_UserName.Text="";  
     TB_Pwd.Text="";  
     TB_Pswd.Text="";  
                                   }  
                       }  
 
private  void  BT_reset_Click(object  sender,  System.EventArgs  e)  
 {  
           Response.Redirect("Register.aspx");  
                       }  
           }  
}

解决方案 »

  1.   

    sa的密码是空吗 connstr="server=localhost;database=aspnet;uid=sa;pwd=";  
    ---------------------------
     connstr="server=.;database=aspnet;uid=sa;pwd=";
      

  2.   

    把连接串贴出来吧.
    还有,看看sql的设置,是否是混合登陆模式,这个要取决于你的连接串.
      

  3.   

    telnet 127.0.0.1 1433
    看看通不通
      

  4.   

    还有,看看sql的设置,是否是混合登陆模式,这个要取决于你的连接串.
    ---------------------------
    这句是关键!以前偶的就是设成了windows,搞半天连不上。
      

  5.   

    sql 服务未打开,你是连接本地数据库的.
    启动sql服务管理器,再打开企业管理器看看那个asp.net的数据库是否存在(保险起见)