ASP.NET 连接 SQLServer 2000 登录错误
程序猿DD
Java领域优质创作者
博客专家认证 2009-03-02 11:52:56 一直都是用Oracle和MySQL,最近接手学长的一个学校的系统,遇到点问题,不知道有哪个朋友碰到过~困惑了几天了~
错误是出现在:
行 34:myConnection.Open();
报的是:用户 'PERSONAL-8FC78E\IUSR_PERSONAL-8FC78E' 登录失败。
web.config中配置的连接字段是:<add key="conn1" value="workstation id='WC-NB';packet size=4096;integrated security=SSPI;data source=(local);persist security info=False;initial catalog=doudou" />
启动ASP.NET服务,SQLServer服务,IIS中都配置没有问题,当与数据库建立连接时,即出现上面的错误。之后我去企业管理器的安全性中有3个名称分别是:
BUILTIN\Administrators
PERSONAL-8FC78E\Administrators
sa
他们都是System级别的角色
这个3个都与所报的用户'PERSONAL-8FC78E\IUSR_PERSONAL-8FC78E' 不符合。
开始一直没怀疑这个连接的正确性,因为这个系统是当前学校一直在用的,是我的学长做的。现在仔细看连接字段,有1个疑问:这个字符串中没有uid和pwd那他是以什么身份登录的呢?
为了测试下这个连接字段是否可用,我在C#命令行工程里试了一下,具体代码是这样的:
SqlConnection myConnection = new SqlConnection("workstation id='WC-NB';packet size=4096;integrated security=SSPI;data source=(local);persist security info=False;initial catalog=doudou");
myConnection.Open();
SqlCommand myCommand = new SqlCommand("select * from timesetting where type='7'", myConnection);
SqlDataReader sdr;
sdr=myCommand.ExecuteReader();
sdr.Read();
DateTime now = System.DateTime.Now;
DateTime startTime = System.DateTime.Parse(sdr["starttime"].ToString());
Console.Write(startTime);
myConnection.Close();
这个可以正确显示出startTime,说明这个连接是有效的,并且服务器也是在正常工作的。但是为什么在WEB里的时候缺发生了这样一个错误呢?