Lm th? no ? t?o m?t k?t n?i c s? d? li?u t? m?t trang ASP trong IIS

D?ch tiu ? D?ch tiu ?
ID c?a bi: 300382
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

C r?t nhi?u cch ? k?t n?i v?i c s? d? li?u. i?u ny bi vi?t-by-step cung c?p m?u k?t n?i dy cho cc lo?i c s? d? li?u v k?t n?i c s? d? li?u.

Yu c?u

Sau y l cc yu c?u ? k?t n?i ?n c s? d? li?u:
  • Active Server Pages (ASP) cho php thng tin trn Internet D?ch v? my ch? Web (IIS) Phin b?n 5.0 v?i Microsoft d? li?u truy c?p cc thnh ph?n (MDAC) Phin b?n 2,5 ho?c 2.6 (v?i m?t c s? d? li?u my bay ph?n l?c)
  • K?t n?i t?i c s? d? li?u ?a phng ho?c t? xa
  • ASP b?t Microsoft Internet Explorer phin b?n 5.0 ho?c sau ny

M?u c s? d? li?u k?t n?i chu?i

Nh?ng v d? ny l nh?m m?c ch minh ch?ng. B?n ph?i dn m? ny trong m? ASP c?a b?n ? k?t n?i v?i cc quy ?nh c s? d? li?u. Lu ? r?ng b?n ph?i thay ?i cc y?u t? nh c s? d? li?u tn, my ch? tn, c s? d? li?u v? tr, tn ngu?n d? li?u (DSN), v nh v?y.

Microsoft Access

N?u khng c DSN
<%
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\mydatabase.mdb"
%>
				
OLE DB
<%
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=c:\mydatabase.mdb"
%>
				
T?p DSN
<% Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "FILEDSN=ADSN"
%>
				
DSN v khng c ID ng?i dng/m?t kh?u
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSNname"
%>
				
V?i DSN v ID/m?t kh?u ng?i dng
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSNname","username","password"
%>
				
N?u khng c DSN, dng m?t ?ng d?n v?t l? nh l m?t ti li?u tham kh?o
<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=c:\mydatabase.mdb" 
Conn.Open DSNtest
%>
				
N?u khng c DSN, b?ng cch s? d?ng Server.MapPath

LU ?: Server.MapPath l con ?ng t? my ch? Web g?c. Theo m?c ?nh, y l C:\Inetpub\Wwwroot.
<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=" & Server.MapPath("/databases/mydatabase.mdb")
Conn.Open DSNtest
%>
				

Microsoft SQL Server

OLE DB
<%
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.open "PROVIDER=SQLOLEDB;DATA SOURCE=sqlservername;UID=username;PWD=password;DATABASE=mydatabase "
%>
				
V?i DSN
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=mydatabase"
%>
				
N?u khng c DSN
<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=mydatabase"
Conn.open DSNtest
%>
				

Microsoft Visual FoxPro

N?u khng c DSN
<%
Set Conn = Server.CreateObject("ADODB.Connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:\databases\mydatabase.dbc"
Conn.Open ConnStr
%>
				

Oracle

ODBC v?i DSN
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.cursorlocation=adUseClient   
' requires use of adovbs.inc; numeric value is 3
Conn.open "DSN=test;UID=name;PWD=pass"
%>
				
OLE DB
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.cursorlocation=adUseClient   
' requires use of adovbs.inc; numeric value is 3
DSNTest="Provider=MSDAORA.1;Password=pass;User ID=name;Data Source=data.world"
Conn.open DSNtest
%>
				



THAM KH?O

? bi?t thm thng tin v? lo?i d? li?u, k?t n?i d? li?u, ho?c Cc thnh ph?n MDAC, xem Web site sau c?a Microsoft:
http://MSDN.Microsoft.com/en-US/Data/aa937729.aspx






Thu?c tnh

ID c?a bi: 300382 - L?n xem xt sau cng: 26 Thang Tam 2011 - Xem xt l?i: 2.0
T? kha:
kbhowto kbhowtomaster kbmt KB300382 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:300382

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com