iis+sql2005,求连接方式
发布网友
发布时间:2024-01-05 19:13
我来回答
共1个回答
热心网友
时间:2024-01-06 18:38
ASP连接MSSQL2005和MSSQL2000数据库通用代码
<%
'ASP连接MSSQL2005和MSSQL2000数据库通用代码
Dim ConnStr
'sql数据库连接参数:数据库名、用户密码、用户名、连接名(本地用local,外地用IP)
Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName
SqlDatabaseName = "Location"
SqlPassword = "password"
SqlUsername = "sa"
SqlLocalName = "(local)"
'SqlLocalName = "192.168.1.15"
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
Set Rs=Server.CreateObject("Adodb.RecordSet")
Sql="Select top 5 Location from Location Order By ID asc"
Rs.Open Sql,Conn,1,1
If Rs.Bof and Rs.Eof Then
Response.Write "暂无数据"
Response.End
Else
Do while Not Rs.Eof
Response.Write Rs("Location") & "<br>"
Rs.MoveNext
Loop
End If
Rs.Close
Set Rs=Nothing
%>