Solution One:
Configure the Access database tutorial driver and database file name in Web.config.
Please look at the code
<appSettings>
<add key= "Dbdriver" value= "provider=microsoft.jet.oledb.4.0; Data Source = "/>
<add key= "dbname" value= "Company.mdb"/>
</appSettings>
Get the Access database link string in the database access layer, such as OleDBHelper.cs.
/**////<summary>
To obtain a database join string from web.config
</summary>
To get the database name from the configuration file
public static readonly String dbname = ConfigurationManager.AppSettings.Get ("dbname"). ToString ();
Get database driver from configuration file
public static readonly String dbdriver = ConfigurationManager.AppSettings.Get ("Dbdriver"). ToString ();
Get the database connection string
private static string dbconnectionstring = Dbdriver + HttpContext.Current.Server.MapPath ( HttpContext.Current.Request.ApplicationPath + "/app_data/") + dbname;
To establish a database connection object
private static OleDbConnection oledbconn = new OleDbConnection (dbconnectionstring);
After this setting, the database can be accessed correctly by the above code, regardless of any subdirectories.
Solution Two:
<appSettings>
<add key= "sqlconnstring" value= "Provider=Microsoft.Jet.OLEDB.4.0;Data source="/>
<add key= "DBPath" value= "~/app_data/mydata.mdb"/>
</appSettings>
In the data access class in the program I take "sqlconnstring" and "DBPath" out to connect to a string "CONN_STRING_NON_DTC"
public
static readonly string CONN_STRING_NON_DTC = system.configuration.configurationmanager.appsettings[" Sqlconnstring "]. ToString () + System.Web.HttpContext.Current.Server.MapPath (configurationmanager.appsettings["DBPath"]) + ";";