Because access is a file database, you must be able to map access to access files in ASP. NET:
Method 1: Set the connection string in deleettings
Web. config Configuration
<Deleetask>
< Add key = " Provider " Value = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " />
< Add key = " Dbpath " Value = " ~ /DB \ data. MDB " /> // Note that ~ must be added ~ /, Representing the root directory </Appsettings>
Concatenate database connection strings through server. Map ()
/// <Summary>
/// Connection string
/// </Summary>
Private String connectionstring = System. configuration. configurationmanager. configurettings [ " Provider " ]. Tostring () + System. Web. httpcontext. Current. server. mappath (configurationmanager. deleetpipeline [ " Dbpath " ]) + " ; " ;
Method 2: connect to access using sqldatasource
Web. config Configuration
< Connectionstrings >
< Add name = " Websiteconnectionstring " Connectionstring = " Provider = Microsoft. Jet. oledb.4.0; Data Source = | datadirectory | aisino_data.mdb " Providername = " System. Data. oledb " /> // Note: datadirectory cannot be changed. Otherwise, "invalid file name error" will occur "! This indicates that it cannot be modified. Your database must be stored in app_data.
In this way, access through configurationmanager. connectionstrings ["websiteconnectionstring"]. connectionstring.