含有 ‘Asp’標籤(tag)的文章們

ASP Connection to Sql Server Example

‘Create DB Connection
set Conn = Server.CreateObject(“ADODB.Connection”)
Conn.Open  “Provider=SQLOLEDB;Data Source=GBUTEST-DB;Initial Catalog=Northwind;User Id=sa;Password=XXXXX;”
‘Create ADO SQL RecordSet
set rs = Server.CreateObject(“ADODB.recordset”)
rs.Open “SELECT [ShipperID],[CompanyName],[Phone] FROM [Northwind].[dbo].[Shippers]“, Conn
response.write(“<TABLE BORDER=1> <TR BGCOLOR=lightyellow>”)
‘Print Table Header
For each h in rs.fields
response.write “<TD>” & h.Name & “</TD>”
next
response.write(“</TR>”)
‘Extract Data From RecordSet
rs.MoveFirst
While Not rs.EOF
response.write(“<TR>”)
for each x in rs.fields
‘response.write(x.name)
‘response.write(” = “)
response.write “<td>” & x.value & “</td>”
next
rs.MoveNext
response.write(“</TR>”)
Wend
response.write(“</TR></TABLE>”)
Conn.Close
Set Conn=Nothing

Continue reading »

ASP 適用的DB連線字串

資料來源:http://blog.yam.com/davidbull/article/17875194
因應各種資料庫,我列出以下資料庫的連接語法如下:
註:不可分行(除非使用 & _ 連結兩行字串才可分行)。在這裏分行是為了方便閱讀。
[ ] 內的東西若設了密碼才需要用到,沒設密碼則必須刪除。使用連線字串時請刪除「[」和「]」。
(資料來源:http://www.class2u.com/book/ultradev4/connection.htm)
Microsoft Access
1.Driver={Microsoft Access Driver (*.mdb)};Dbq=資料庫;[Uid=使用者名稱;Pwd=密碼;]
2.Provider=Microsoft.Jet.OLEDB.4.0;Data Source=資料庫;[User Id=使用者名稱;Password=密碼;]
Oracle
1. Driver={Microsoft ODBC for Oracle};Server=資料庫;[Uid=使用者名稱;Pwd=密碼;]
2. Provider=OraOLEDB.Oracle;Data Source=資料庫;[User Id=使用者名稱;Password=密碼;]
dBase
Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=資料庫;
Microsoft Text Driver
1. Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=資料庫;Extensions=asc,csv,tab,txt;
Persist Security Info=False;
2. Provider=Microsoft.Jet.OLEDB.4.0;Data Source=資料庫;
Extended Properties=’text;FMT=Delimited’
Microsoft SQL Server
1. Driver={SQL Server};Server=伺服器;Database=資料庫;
[Uid=使用者名稱(預設帳戶為sa);Pwd=密碼;]
2. Provider=SQLOLEDB;Data Source=伺服器;Initial Catalog=資料庫;
[User Id=使用者名稱(預設帳戶為sa);Password=密碼;]
MySQL
driver={mysql};database=資料庫;option=16386;[uid=使用者名稱;pwd=密碼;]
Visual Foxpro
Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;
SourceDB=資料庫;Exclusive=No;
建立連線時,我們必須先建立連線元件,並因應該資料庫類型以上述連線方式連接資料庫。
假設資料庫路徑為在網頁底下的 abc.mdb (Access資料庫),使用者名稱為 abc 、密碼為 test ,你可以這樣作:
<%
Set objDBConn=Server.Createobject(“ADODB.connection”)   ’建立連線元件
objDBConn.open ”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & _
Server.MapPath(“abc.mdb”) & _
“;User Id=abc;Password=test;”
‘用連結字串開啟OLE DB的Access資料庫。注意,若您的資料庫沒設使用者名稱及密碼,則不需User Id及Password屬性。
‘此時資料庫已經開啟,我們可以執行SQL指令或是建立資料集元件,請參閱其他相關文章。
‘當執行完SQL指令或其他相關操作,我們可以叫那元件「回家睡覺」了。
objDBConn.Close
Set objDBConn=Nothing
‘關閉資料庫元件連接,釋放系統資源,「回家睡覺」去
%>

Continue reading »

ASP 寄送 EMail

CDONTS.NewMail是IIS提供的物件,必須要安裝IIS後,才能使用….
‘建立一個CDONTS.NewMail物件
Set mail = Server.CreateObject(“CDONTS.NewMail”)
‘設定收件者:TO 屬性
mail.To = “kl.cheng@gmail.com”
‘設定寄件者:FROM 屬性
mail.From = “kuangliang2000@gmail.com”
‘設定主旨:SUBJECT屬性
mail.Subject = “一封測試信件”
‘設定郵件內容:BODY 屬性
body = “kl.cheng 你好,這是一封測試信件,為確保系統上線正常運作,收到測試信後,請回覆給寄件者,謝謝!”
mail.Body = body
‘加入附件
mail.AttachFile Server.MapPath(“mail.gif”)
‘送出郵件
mail.Send,

Continue reading »

Run ASP on Apache Server

If you want to use VBScript for ASP-Webpages, then download Chili!ASP
from http://www.chilisoft.com and install it. But remember that the
above mentioned software only runs on Apache 1.3.20 and below … but
it works fine !
You can find more downloads for Apache at
http://modules.apache.org ,search for ASP and that’ll give you three
modules to download !
So have fun using ASP [...]

Continue reading »