在sql server2000中的数据库pubs中建立了表identity存储sno ,pwd 两项数据现用如下语句访问
protected System.Data.SqlClient.SqlConnection conn;
string Sno=SnoTextBox.Text.ToString();
string Pwd=PwdTextBox.Text.ToString();
string connectString="server=localhost;database=pubs;uid=sa;pwd=";
conn=new SqlConnection(connectString);
conn.Open();
SqlCommand command=new SqlCommand("select * from identity where sno='"+Sno+"'and Pwd='"+Pwd+"'",conn);
SqlDataReader reader=command.ExecuteReader();
if(reader.Read()==true)
{
Session["Sno"]=Sno;
Response.Redirect("MainPage.aspx");
}
else
{
        msg.Text="密码错误!请从新输入!";
        return;
}
运行提示:
异常详细信息: System.Data.SqlClient.SqlException: SQL Server 不存在或访问被拒绝。
源文件: conn.Open();sql server2000装在c:\默认路径
iis路径为 D:\myweb\请问如何解决,第一次用vs.net c# 编程,请高手多多指教。
不胜感激!!

解决方案 »

  1.   

    跟安装路径无关,你是怎么配置SQL服务器的,参考
    http://support.microsoft.com/default.aspx?scid=kb;en-us;315159
      

  2.   

    1.改string connectString="server=localhost;database=pubs;uid=sa;pwd=";
    为"data source=localhost;initial catalog=pubs;user id=sa;password=;packet size=4096 ;Provider=SQLOLEDB;"
    2.改SqlCommand command=new SqlCommand("select * from identity where sno='"+Sno+"'and Pwd='"+Pwd+"'",conn);
    为SqlCommand command=new SqlCommand("select * from [identity] where sno='"+Sno+"' and Pwd='"+Pwd+"'",conn);试试