asp 连接sql2005

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>


<%
DB_ServerName ="192.168.1.4,1433" '数据库名称(IP+实例名)
DB_UserName = "sa" 'SQL用户名
DB_PassWord = "123" 'SQL用户密码
DB_DateBase = "stu" '数据库名
DB_Provider = "SQLNCLI" '驱动程序
DB_ConnStr = "Provider="&DB_Provider&"; UID="&DB_UserName&"; Pwd="&DB_PassWord&"; database="&DB_DateBase&"; Server="&DB_ServerName&";"
Set Conn = Server.CreateObject("ADODB.Connection")
set Rs=Server.CreateObject("ADODB.RecordSet")
sql="select * from stu_inf"
Conn.Open  sql, DB_ConnStr ,1,3
Rs.open   sql, DB_ConnStr ,1,3


If rs.bof or rs.eof then
    Response.Write"<span>没有任何记录</span>"
Else
    while not rs.eof
        response.Write rs("name")&"<br>"
rs.movenext
    wend
End If

%>


</body>
</html>

你可能感兴趣的:(sql,SQL Server,XHTML,VBScript,asp)