Since I was a self-taught program, I have been using SQL Server databases. Recently, I made an access demo for a friend and found that there are great differences in database connections, on the web. configure the connection string in config and obtain it in the background. Here, I save two values and separate the paths of the provider and assess database files, as shown below:
<Connectionstrings> <Add name = "access_con" connectionstring = "provider = Microsoft. Jet. oledb.4.0; Data Source ="/> <Add name = "access_path" connectionstring = "~ /App_data/DB. mdb "/> </connectionstrings>
The relative path is stored in the configuration file, so you need to convert it to an absolute path after reading it in the background, as shown below:
Private string con_str = configurationmanager. connectionstrings ["access_con"]. connectionstring + httpcontext. Current. server. mappath (configurationmanager. connectionstrings ["access_path"]. connectionstring );
The main difference lies in the connection string. Other operations are basically the same as those of sqlserver, just replace the namespace and class with the olddb. Note the following when writing a connection string in webconfig:
<Add name = "access_con" connectionstring = "provider = Microsoft. Jet. oledb.4.0; Data Source ="/>
The data source in the code above must contain spaces and cannot be written as datasource. Otherwise, an error will be reported during program execution, as shown below:
This error can be avoided if you are careful.