下面是源代码,总提示连接失败,结果代码: 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>
<%@ 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>
{}
Server=机器名; Data Source=库名; User ID=sa; Password=密码;
server=sql服务;database=数据库名;uid=用户名;pwd=密码
语句是"server=(local);database=data;trusted_connection=yes";谢谢大家!