The database connection in webconfig does not support server. mappath. Generally, we can only write the physical path of the database file, which makes website migration very inconvenient. I found a solution on the internet today and shared it with you. See the following Code :
< Connectionstrings >
< Add Name = "Connstr_access"
Providername = "System. Data. oledb"
Connectionstring =
"Provider = Microsoft. Jet. oledb.4.0; Data Source = | datadirectory | \ cms. mdb ;"
/>
</ Connectionstrings >
| Datadirectory | it will be automatically parsed to app_data
Here is the description of msdn:
Replace string with datadirectory
AttachdbfilenameHas been extended in ADO. NET 2.0 and introduced| Datadirectory |Replacement string (included in the pipeline symbol.DatadirectoryAndAttachdbfilenameIn combination with the relative paths that can indicate data files, developers can create connection strings based on the relative paths of the database source (without specifying the full path.
DatadirectoryThe physical location of a vertex depends on the ApplicationProgram. In this example, the northwind. MDF file to be appended is located in the \ app_data folder of the application.
Data Source = . \ Sqlexpress; Integrated Security = True ;
User instance = True ;
Attachdbfilename = | Datadirectory | \ App_data \ northwind. MDF;
Initial catalog = Northwind;
UseDatadirectoryThe path of the result file in the directory structure cannot be higher than the directory pointed to by the replacement string. For exampleDatadirectoryIf it is c: \ appdirectory \ app_data, the connection string shown above is valid because it is under c: \ appdirectory. However, if you tryDatadirectorySpecified| Datadirectory | \ .. \ dataAn error occurs because \ data is not a subdirectory of \ appdirectory.