Various database connection codes in ASP

Source: Internet
Author: User
Tags dsn access database oracle database
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
%>



Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.