You are using windows integrated authenticationwhen you run the sql in vs.net, it runs as you, since you have more privileges, so it runs okbut when the page is run on the web server, it runs as "ASPNET" account, which has very limited privileges, that is why it failedyou should either add ASPNET account to your database or turn on SQL authentication, create an account or use "sa", and use a connection string like
"Server=yourServerName;Database=YourDBName;UID=YourDBLogin;PWD=YourDBPassword;"

解决方案 »

  1.   

    你的SQL是系统认证的。他们的一些写法有些不同的。这是用SA的Sqlconnection Gj_conn = new  SqlConnection("server=yu;database=Gujia;uid=sa;pwd="
      

  2.   

    各位老大的意思是如果用widows的系统认证就无法连接成功?我的sqlserver在安装时就默认为windows系统认证,该怎样改呢?
      

  3.   

    连接串中加上pwd=yourpasswd;
    自动生成的连接串是不带密码的,所以只有密码为空的时候能执行。手动添加上就可以了。
    你用windows验证它用 aspnet用户去访问数据库了,
    或者改成SQL验证
    或者给 aspnet访问的数据库的权限
      

  4.   

    集成验证时
    在 windows程序中它是用你当前的用户去访问数据库的
    在WEB程序中它是通过aspnet用户
    所以出现了不能访问的问题
      

  5.   

    widows的系统认证是可以连接的,
    不过需要自己在使用者中添加账号权限
    连接字串是:
    Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;
      

  6.   

    我重新配置了一下我的sql server,加上了sa用户验证就好了.谢谢大家!
      

  7.   

    widows的系统认证是可以连接的,
    不过需要自己在使用者中添加账号权限
    连接字串是:
    Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;