Friday, 8 October 2010

[ASP ][Library]ASP Connection Database

ACCESS:

<%
connStr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &Server.Mappath("data.mdb")
Set conn=Server.CreateObject("ADODB.Connection")
conn.open connStr

conn.close()

Set conn=nothing
%>

OR
<%
Dim conn
Sub init()
set conn=server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.MapPath("database/game_cards.mdb"))
End Sub
Sub destroy()
conn.close()
Set conn=nothing
End Sub

%>
1. Connect to a Microsoft Access Database from ASP using a DSN 
 
Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open "DSN=;UID=;PWD="
oConnection.Close
2. Connect to a Microsoft Access Database from ASP using DSN-less ODBC connection
 
Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
Server.MapPath("") & ";UID=;PWD="
oConnection.Close
Set oConnection = Nothing

3. Connect to a Microsoft Access Database from ASP using DSN-less OLEDB  connection 
 
Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & 
Server.MapPath("") & ";"
oConnection.Close
Set oConnection = Nothing


SQL SERVER
1. Connect to a MS SQL Server database with OLE DB:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=SQLOLEDB; Data Source=YOUR_SERVER_NAME; Initial
Catalog=your_database_name; User ID=your_username; Password=your_password"
objConn.Close
Set objConn = Nothing

2. Connect to a MS SQL Server database with SQL Driver:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Driver={SQL Server};" & _
"Server=YOUR_SERVER_NAME;" & _
"Database=your_database_name;" & _
"Uid=your_username;" & _
"Pwd=your_password;"
objConn.Close
Set objConn = Nothing


No comments:

Post a Comment