我是.net这学者,在调用database文件中pubs.mdf   和pubs_log.df文件中数据时,发生下列错误!default.aspx  中代码是:<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
     <asp:ListBox ID="ListBox1" runat="server" Height="161px" Width="240px" ></asp:ListBox>
    </div>
    </form>
</body>
</html>和default.aspx.cs中的代码是:using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(! IsPostBack) 
        {
            SqlConnection conn = new SqlConnection("server=(local); Initial Catalog=pubs; Integrated Security=True ");
                
            string strSql = "select pub_name from publishers";
            SqlCommand comm=new SqlCommand(strSql,conn);
            try
            {
                conn.Open();
                SqlDataReader sdr=comm.ExecuteReader();
                while(sdr.Read())
                {
                    ListItem item = new ListItem(sdr["pub_name"].ToString());
                   ListBox1.Items.Add(item);
                }                  sdr.Close();
              }
            catch(SqlException ex)
            {
                Response.Write(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
我用的是visualstudio2005和sql2005,浏览时显示下列错误!哪位大哥能指点一下,先谢谢了!
System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 "pubs"。登录失败。用户 'FD2B1E776E06469\ASPNET' 登录失败。 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 在 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) 在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) 在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) 在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) 在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) 在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) 在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) 在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 在 System.Data.SqlClient.SqlConnection.Open() 在 _Default.Page_Load(Object sender, EventArgs e) 

解决方案 »

  1.   

    登录失败。用户 'FD2B1E776E06469\ASPNET' 登录失败。登录的用户名错了,数据库的
      

  2.   

    用户名或密码不正确
    SQL Server Management Studio Express,
    选择身份验证为“SQL Server和 Windows ”
    数据库下->安全性>用户>用户名和密码是否正确
      

  3.   

    SqlConnection conn = new SqlConnection("server=(local); Initial Catalog=pubs; Integrated Security=True "); 
    访问你的数据库需要用户名和密码吧
      

  4.   

                SqlConnection conn = new SqlConnection("server=(local); Initial Catalog=pubs; Integrated Security=True "); 
    改为
                SqlConnection conn = new SqlConnection("server=(local); Initial Catalog=pubs; Integrated Security=True userID=你数据库设置的用户名;pwd=密码 ");