Various database connection codes
I have nothing to do today. I have summarized the connections to various databases and share them with you:
MS Access database connection
Use DSN to connect without the user name and password:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. open "YourDSNName"
%>
Connect with DSN and have the user name and password:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. open "YourDSNName", "username", "password"
%>
Use the actual absolute path of the database to connect:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Strconn = "DRIVER = {Microsoft Access Driver (*. mdb )};"
Strconn = Strconn & "DBQ = e: yanhangdatabase. mdb"
Conn. Open Strconn
%>
Use the actual database relative path to connect:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Strconn = "DRIVER = {Microsoft Access Driver (*. mdb )};"
Strconn = Strconn & "DBQ =" & Server. MapPath ("/database/yanhang. mdb ")
Conn. Open Strconn
%>
Ms SQL Server database connection
Connect with DSN:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. open "DSN = MyDSN; UID = user; PWD = password; DATABASE = databasename"
%>
No DSN connection required:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
DSNtemp = "DRIVER = {SQL Server}; SERVER = ServerName; UID = USER; PWD = password; DATABASE = databasename"
Conn. open DSNtemp
%>
FoxPro database connection
<%
Set Conn = Server. CreateObject ("ADODB. connection ")
ConnStr = "Driver = Microsoft Visual Foxpro Driver; UID = userID; SourceType = DBC; SourceDB = C: yanhangdatabase. dbc"
Conn. Open ConnStr
%>
Oracle Database connection:
<%
Set conn = server. createobject ("adodb. connection ")
Conn. cursorlocation = adUseClient
DSNTemp = "Provider = MSDAORA.1; Password = xxxxx; User ID = yanhang; Data Source = xxx. world"
Conn. open DSNtemp
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service