Data | database | Database connection various database connection codes
Today to stay there is nothing to do, the connection of various databases summed up a bit, now take out to share with you:
MS Access database connection
Connect with DSN and no username and password:
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Yourdsnname"
%>
Connect with DSN with user name and password:
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Yourdsnname", "username", "password"
%>
Connect with the actual database absolute path:
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
strconn= "Driver={microsoft Access DRIVER (*.mdb)}; "
Strconn=strconn & "Dbq=e:\yanhang\database.mdb"
Conn. Open strconn
%>
Connect with the actual database relative path:
<%
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:
<%
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:\yanhang\database.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
%>