string strcon,strsql;
strcon="integrated security=SSPI;data source=xuwei;initial catalog=bank";
strsql="select * from history";
System.Data.SqlClient.SqlDataAdapter sda=new SqlDataAdapter(strsql,strcon);
DataSet ds =new DataSet();
sda.Fill(ds,"history");
DataGrid1.DataSource=ds.Tables["history"];
当在C#应用程序时,可以运行,
但是在Web应用程序时却登录失败.
用的是NT的用户认证
错误信息::
用户 'XUWEI\ASPNET' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 用户 'XUWEI\ASPNET' 登录失败。源错误:
行 29: System.Data.SqlClient.SqlDataAdapter sda=new SqlDataAdapter(strsql,strcon);
行 30: DataSet ds =new DataSet();
行 31: sda.Fill(ds,"history");
行 32: DataGrid1.DataSource=ds.Tables["history"];
行 33:
源文件: c:\inetpub\wwwroot\webapplication2\webform1.aspx.cs 行: 31 堆栈跟踪:
[SqlException: 用户 'XUWEI\ASPNET' 登录失败。]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication2\webform1.aspx.cs:31
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
这句没看过。
看起来像是连接数据库的字符串。
但没看过这种连法的。
看起来,你是SQL SERVER的数据库
应该是
strcon="server=你的SERVER服务器名;uid=你的用户名 ;pwd=你的密码;database=你的数据库名";
楼主看一下计算机管理里面的用户里面是否已经禁用了aspnet和iusr_机器名