private void Page_Load(object sender, System.EventArgs e)
{ string str="user ID=sa;Password=;Server=DomainName;database=pubs";
SqlConnection conn=new SqlConnection(str);
SqlDataAdapter adapter=new SqlDataAdapter("select * from authors",conn);
DataSet ds=new DataSet();
adapter.Fill(ds,"authors");<-====这里出错
this.DataGrid1.DataSource=ds.Tables["authors"];
this.DataGrid1.DataBind(); }
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: SQL Server 不存在或访问被拒绝。源错误:
行 34: SqlDataAdapter adapter=new SqlDataAdapter("select * from authors",conn);
行 35: DataSet ds=new DataSet();
行 36: adapter.Fill(ds,"authors");//这一行为红色,提示错误
行 37: this.DataGrid1.DataSource=ds.Tables["authors"];
行 38: this.DataGrid1.DataBind();
源文件: c:\inetpub\wwwroot\webapplication5\webform1.aspx.cs 行: 36 堆栈跟踪:
[SqlException: SQL Server 不存在或访问被拒绝。]
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)
WebApplication5.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication5\webform1.aspx.cs:36
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573