人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

asp不用DSN訪問數據庫

asp不用DSN訪問數據庫

更新時間:2022-08-20 文章作者:未知 信息來源:網絡 閱讀次數:

一個DSN連接需要服務器的系統管理員在服務器上用控制面板中的ODBC工具設置一個DSN,或者使用一個第三方的服務器組件,讓你的ASP腳本在需要時通過修改注冊表建立DSN.

  一個DSN連接通常需要的參數有:DSN名,用戶名,口令,例如我們用用戶名"student",口令"magic",通過DSN"student"建立連接:
  1. set conntemp=server.createobject("adodb.connection")
  2. conntemp.open "DSN=Student; uid=student; pwd=magic"

  3. set rstemp=conntemp.execute("select * from authors")

  如果我們沒有DSN,該怎么做呢?

  但是我們知道文件名(比如,Access,Paradox,FoxPro的數據庫)或者數據源名(例如,SQLserver的數據庫).這里有一個方法,我們不要DSN就可以訪問數據庫.注意,你必須知道實際的文件路徑!比如: "C:\thatserver\account17\nwind.mdb".

  幸好,方法 server.mappath 可以返回服務器上的地址.
  
  1. set conntemp=server.createobject("adodb.connection")

  2. cnpath="DBQ=" & server.mappath("yourtable.mdb")

  3. conntemp.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & cnpath

  4. set rstemp=conntemp.execute("select * from authors")

  <HTML><HEAD>

  <TITLE>nwind.asp</TITLE>

  <body bgcolor="#FFFFFF"></HEAD>
  <%

  set conntemp=server.createobject("adodb.connection")
  ' 不用DSN建立連接

  DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "

  DSNtemp=dsntemp & "DBQ=" & server.mappath("nwind.mdb")

  conntemp.Open DSNtemp

  ' 不用DSN建立連接
  set rstemp=conntemp.execute("select * from customers where country='germany'")

  howmanyfields=rstemp.fields.count -1

  %>
  <table border=1>

  <tr>
  <% 'Put Headings On The Table of Field Names

  for i=0 to howmanyfields %>
  <td><b><%=rstemp(i).name %></B></TD>
  <% next %>
  </tr>
  <% ' Now lets grab all the records

  do while not rstemp.eof %>
  <tr>
  <% for i = 0 to howmanyfields%>
  <td valign=top><%=rstemp(i)%></td>
  <% next %>
  </tr>
  <% rstemp.movenext

  loop

  rstemp.close

  set rstemp=nothing

  conntemp.close

  set conntemp=nothing %>
  </table>

  </BODY>

  </HTML>



  下面是典型的DRIVER參數值:
  {Microsoft Access Driver (*.mdb)}
  driver=SQL Server; server=127.0.0.1
  ^ SQLServer的IP地址

  不通過數據源訪問SQL和ACCESS
  Using SQL Server 6.5:
  set Conn = Server.CreateObject("ADODB.Connection")
  Conn.Open "driver=SQL Server; server=server_name; uid=your_UID; pwd=your_PW; database=your_database;"

  Using Access:
  set Conn = Server.CreateObject("ADODB.Connection")
  Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\www\db\guestbook.mdb"

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 城口县| 扎鲁特旗| 曲沃县| 上杭县| 陇川县| 洛南县| 抚宁县| 孝昌县| 蒙城县| 夏津县| 阿尔山市| 泰和县| 五莲县| 财经| 泌阳县| 隆德县| 南宁市| 桐庐县| 平罗县| 江西省| 长宁区| 离岛区| 无锡市| 舟山市| 包头市| 定远县| 宁海县| 肇州县| 宝应县| 商河县| 广平县| 乐亭县| 南涧| 玉龙| 当雄县| 平远县| 济源市| 云林县| 衡山县| 庆元县| 攀枝花市|