asp中2种链接数据库的conn.asp写法,哪个更好?
2种链接数据库的conn.asp文件的写法,哪个更好?更安全,速度更快?或者朋友们还有什么更好更快的方法??
1:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("Data/data.mdb")
%>
2:
<%
dim conn
dbpath="data.mdb"
Set conn = Server.CreateObject
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath
conn.open connstr
If Err Then
err.Clear
Set conn = Nothing
Response.Write "数据库连接出错,请稍候访问。"
Response.End
End If
'新闻阅读模块
Dim News_title,News_content
Sub ReadNews
set rs1=server.createobject
sql1="select id,title,content from article where id="& ID
rs1.open sql1,conn,3,3
News_title=rs1
News_content=rs1
rs1.close
set rs1=Nothing
End Sub
%>