ASP通过SQL Server Native Client连接数据库示例
<%@LANGUAGE
=
"
VBSCRIPT" CODEPAGE
=
"
65001"%
>
<!doctype html
>
<html
>
<head
>
<meta charset
=
"
utf-8"
>
<title
>ASP
链
接SQL
Server Native Client
10
</title
>
</head
>
<body
>
<%
Response.
Write(
"
abc")
%
>
<br/
>
<%
Dim Conn, ConnStr
Set Conn
=
Server.
CreateObject(
"
Adodb.Connection")
'
sql server 2008是SQL Server Native Client 10.0, 用 SQLNCLI10'
'
sql server 2005是SQL Server Native Client 9.0, 用SQLNCLI'
'
其他往后的版本依次修改SQLNCLIxx,如11,12等,主要取决于安装的NativeClient的版本。 如果链接低级版本,如SQL Server2000, 需要添加 DataTypeCompatibility=80; '
' '
ConnStr
=
"
Provider=SQLNCLI10;Server=localhost\SQLExpress;Database=dd2014;Uid=sa;Pwd=666666;"
'
'
Conn.Open ConnStr
Dim Sql, Rs
Set Rs
=
Server.
CreateObject(
"
Adodb.RecordSet")
Sql
=
"
SELECT TOP 3 id,title FROM hellose_table ORDER BY id DESC"
Rs.Open Sql,Conn,
1,
1
Dim i
i
=
1
Response.
Write(
"
count:"
&Rs.recordcount
&
"
<br/>")
While
Not Rs.EOF
response.
Write(i
&
"
."
&
Rs(
"
id")
&
"
-- "
&
Rs(
"
title")
&
"
<br/>")
Rs.MoveNext
i
= i
+
1
Wend
%
>
</body
>
</html
>
参考网址:
http://msdn.microsoft.com/zh-cn/library/ms131291.aspx
http://msdn.microsoft.com/zh-cn/library/ms130978.aspx