<DIV class=NewsContent id=NewsContentLabel><P align=center>ASP与SQL数据库连接代码</P><P>//第一种写法:<BR>MM_conn_STRING = "Driver={SQL Server};server=(local);uid=sa;pwd=;database=infs;"<BR>Set conn = Server.Createobject("ADODB.Connection")<BR>conn.open MM_conn_STRING<BR>SET RS=SERVER.CreateObject("ADOBD.recordset")<BR>SQL="SELECT * FROM TABLE ORDER BY ID DESC"<BR>RS.open SQL,CONN,3,3 </P><P>//第二种写法:(DSN连接)</P><P>MM_conn_STRING="DSN=BBS;UID=SA;PWD=12345"<BR>Set conn = Server.Createobject("ADODB.Connection")<BR>conn.open MM_conn_STRING<BR>SET RS=SERVER.CreateObject("ADOBD.recordset")<BR>SQL="SELECT * FROM TABLE ORDER BY ID DESC"<BR>RS.open SQL,CONN,3,3 // 3,3是修改、删除、增加开关!</P><P>//第三种写法:</P><P>MM_conn_STRING_own = "Driver={SQL Server};server=(local);uid=sa;pwd=11111;database=infs;"<BR>Set conn = Server.Createobject("ADODB.Connection")<BR>conn.open MM_conn_STRING_own</P><P>//第四种 - 这种方法用在ACCESS中<BR>strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _<BR>& Server.MapPath("asp.mdb")<BR>set conn = server.createobject("adodb.connection")<BR>conn.open strconn</P></DIV> |
|