Common ways to write connection strings in ASP, including access2007 and other Access connection strings
strConnect = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MyDatabase.mdb;
Access 2007 connection string
strConnect = Provider=Microsoft.ACE.OLEDB.12.0;Mode=Share Exclusive;Data Source=C:/MyDatabase.accdb;
MSSQL Server connection string
strConnect = Provider=SQLOLEDB;Data Source=ServerName/InstanceName;Initial Catalog=DatabaseName;User ID=UserName;Password=password;
Excel connection string
strConnect = Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;HDR=YES;Data Source=C:/MyWorkbook.xls;
The default value of HDR is YES, which means the first line is the field name, otherwise the first line will be the content.
Excel 2007 connection string
strConnect = Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=C:/MyWorkbook.xlsx;
Text file (text file can also be used as a database)
strConnect = Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Text;Data Source=C:/Files/;
Well, the parameter Data Source is the directory name containing the file, not the file name. If the first line of the text file does not contain the field name, you must enter HDR=No (same as Excel) in the parameter Extended Properties to avoid losing the first row of data.
Use connection string
Copy the code code as follows:
Dim conn
SubDBOpen()
Dim db: db=Server.MapPath(zzz.mdb)
Set conn=Server.CreateObject(Adodb.Connection)
On Error Resume Next
conn.Open Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & db
If Err.Number<>0 then
Err.Clear
Response.Write(<h1>The Database link is ERROR</h1>)
Response.End()
End If
On Error GoTo 0
End Sub
CallDBOpen()
… …
conn.CLose() : Set conn=Nothing