using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;namespace copynews
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid MyList;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
string DBPath=System.Configuration.ConfigurationSettings.AppSettings["DBPath"];
string strconn=System.Configuration.ConfigurationSettings.AppSettings["Connection"]+Server.MapPath(DBPath);
OleDbConnection myconnection=new OleDbConnection(strconn);
OleDbDataAdapter mycommand=new OleDbDataAdapter("select * from ggtable",myconnection);
DataSet ds=new DataSet();
mycommand.Fill(ds,"ggtable");
MyList.DataSource=ds.Tables["ggtable"].DefaultView;
MyList.DataBind();
mycommand.Dispose();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;namespace copynews
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid MyList;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
string DBPath=System.Configuration.ConfigurationSettings.AppSettings["DBPath"];
string strconn=System.Configuration.ConfigurationSettings.AppSettings["Connection"]+Server.MapPath(DBPath);
OleDbConnection myconnection=new OleDbConnection(strconn);
OleDbDataAdapter mycommand=new OleDbDataAdapter("select * from ggtable",myconnection);
DataSet ds=new DataSet();
mycommand.Fill(ds,"ggtable");
MyList.DataSource=ds.Tables["ggtable"].DefaultView;
MyList.DataBind();
mycommand.Dispose();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
--------------------------------------------------------------------------------不能使用 '';文件已在使用中。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 不能使用 '';文件已在使用中。源错误:
行 30: OleDbDataAdapter mycommand=new OleDbDataAdapter("select * from ggtable",myconnection);
行 31: DataSet ds=new DataSet();
行 32: mycommand.Fill(ds,"ggtable");
行 33: MyList.DataSource=ds.Tables["ggtable"].DefaultView;
行 34: MyList.DataBind();
源文件: d:\inetpub\wwwroot\copynews\default.aspx.cs 行: 32 堆栈跟踪:
[OleDbException (0x80004005): 不能使用 '';文件已在使用中。]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
System.Data.OleDb.OleDbConnection.InitializeProvider()
System.Data.OleDb.OleDbConnection.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)
copynews._Default.Page_Load(Object sender, EventArgs e) in d:\inetpub\wwwroot\copynews\default.aspx.cs:32
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
string strconn=System.Configuration.ConfigurationSettings.AppSettings["Connection"]+Server.MapPath(DBPath);
===============================================
连接字符串帖出来,
怀疑:1,文件已经被别的程序打开
2,连接字符串有误
<add key="DBPath" value="DB\\db1.mdb"/>
<add key="Connection" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="/>
</appSettings>