下面是源代码,总提示连接失败,结果代码: DB_E_ERRORSOCCURRED(0x80040E21)。 哪位好心人帮我看下是怎么回事。<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"  Inherits="Default2" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!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>
   <script runat="server">
      
       public void page_load(object src, EventArgs e)
       {
           string myconnstring = "Provider=SQLOLEDB;Data Source=WIN-P733RSGTBEJ;Initial Catalog=Northwind;Integrated Security=True";           string strsel = "select * from Region";
           //建立一个dataset实例
           DataSet ds=new DataSet();
           OleDbConnection myconn = new OleDbConnection(myconnstring);
           OleDbDataAdapter myadapter = new OleDbDataAdapter(strsel, myconn);
           myadapter.Fill(ds, "id");
           score.DataSource = ds.Tables["id"].DefaultView;
           score.DataBind();
    }
    </script> 
  </head>
  <body>
  <form runat="server">
  <b>dataset</b>
  <asp:DataGrid ID="score" runat="server" HeaderStyle-BackColor="#aaaadd" AlternatingItemStyle-BackColor="#eeeeee"></asp:DataGrid>
  </form>
  </body>
</html>

解决方案 »

  1.   

    using(SqlDBConnection conn=new SqlDBConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"))
    {}
      

  2.   

    有可能是配置原因,换成用账号连接试试
    Server=机器名; Data Source=库名; User ID=sa; Password=密码;
      

  3.   

    你改一下连接字符串试试用混合模式登陆
    server=sql服务;database=数据库名;uid=用户名;pwd=密码
      

  4.   

    我在网上找了一下资料,用信任连接模式连上了
    语句是"server=(local);database=data;trusted_connection=yes";谢谢大家!