本文介绍了ASP SQL 服务器连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Data Source=123.123.12.123,1234;Database=DatabaseName;User Id=Usernm;Password=abcd1234;"
objConn.Open
DIM mySQL
mySQL = "SELECT * FROM [Users] WHERE [User ID]='1'"
DIM objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.open(mySQL, objConn)
Response.Write objRS("FullName")
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
我想连接到 SQL Server 数据库,读取数据并关闭连接.我研究了这些例子并想出了这个.但它不起作用.请指导我.我哪里错了?
I want to connect to a SQL Server Database, read the data and close the connection. I have studied the examples and came up with this. But its not working. Please guide me. Where am I going wrong?
推荐答案
Dim rs, dbConn
Function OpenDB()
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.ConnectionTimeout = 300
dbConn.CommandTimeout = 300
dbConn.Open "Data Source=123.123.12.123,1234;Database=DatabaseName;User Id=Usernm;Password=abcd1234;"
End Function
Function CloseDB()
Set rs = Nothing
if ucase(TypeName(dbConn)) = "CONNECTION" then
dbConn.Close
Set dbConn = Nothing
end if
End Function
Function OpenRecordSet(recset, tablename)
Call OpenDB()
Set recset = Server.CreateObject("ADODB.Recordset")
recset.Open tablename, dbConn, 0, 1
End Function
Function CloseRecordSet(recset)
Set recset = Nothing
Call CloseDB()
End Function
然后使用
<%
Call OpenDB()
sql = "select from mytable where this = 'that'"
Set rs = dbConn.Execute(sql)
if not rs.EOF then
' do your stuff!
end if
Call CloseDB()
%>
http://www.shiningstar.net/articles/文章/数据库/datafunctions.asp?ID=AW
这篇关于ASP SQL 服务器连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!