Access Connection string
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 "";D ATA Source=c:\myworkbook.xls;
Where the HDR default is yes to the first behavior field name, otherwise the first row 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 files (text files can also be used as databases)
StrConnect = "provider=microsoft.ace.oledb.12.0; Extended properties=text;data source=c:\files\; "
Well, parameter data source is the directory name that contains the file, not the file name. If the first line of a text file does not contain a field name, you must participate in Hdr=no (with Excel) in the parameter extended properties to avoid losing the first row of data.
Using Connection Strings
Copy Code code as follows:
Dim conn
Sub Dbopen ()
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
Resp Onse. Write (' Response.End ()
End-If
on ERROR GoTo 0
End Sub
Call dbopen ()
...
Conn. Close (): Set conn=nothing