kangbit
Sat 22 Aug 2009 10:04:23
ผมลองติดต่อฐานข้อมูลที่เป็น MySQL โดยมีโค้ดดังต่อไปนี้
Dim Conn,Sql,Rs
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=localhost; UID=root; " & _
"pwd=123456;database=thainjr_employee;option=16384;"
Sql="Select * From tbl_employee"
Set Rs=server.CreateObject("Adodb.Recordset")
Rs.Open Sql,Conn,1,3
While Not Rs.eof
Rs.Fields("First_Name").Value
Rs.movenext
wend
Rs.Close()
และพอทดสอบก็เกิด Error ดังกล่าวไม่ทราบว่าเกิดจากอะไรเหรอครับไม่เข้าใจรบกวนช่วยหน่อยนะครับ
Error Type:
Active Server Pages, ASP 0115 (0x80004005)
A trappable error (C0000005) occurred in an external object. The script cannot continue running.
/TVCon_Reservation/Connection/Connection.asp
webmaster
Sun 23 Aug 2009 01:28:43
kangbit
Mon 24 Aug 2009 11:33:09
ผมลองตามโค้ดด้านล่างนี้แล้วนะครับแต่ไม่ได้ครับหา Data Source ไม่เจอ ผมลองทำ MySQL ODBC connection แล้วลอง Test connect แล้วก็ได้นะครับแต่พอเราเขียนโค้ดขึ้นมากลับมี Error ดังที่บอกไปนะครับ
dim adoConn
dim adoRS
dim counter
set adoConn = Server.CreateObject("ADODB.Connection")
set adoRS = Server.CreateObject("ADODB.Recordset")
adoConn.Open "Driver={sqldatabase}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=mysql; Uid=root; Pwd=123456;"
adoRS.ActiveConnection = adoConn
if adoConn.errors.count = 0 then
response.write "<h2>Fields In The 'Contacts' Table:</h2>"
adoRS.Open "describe contacts"
while not adoRS.EOF
response.write adoRS.fields(0).value & "<br>"
adoRS.MoveNext
wend
else
response.write "ERROR: Couldn't connect to database"end if
------------------------------------------------------------------------------
Error Message
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
/TVCon_Reservation/Connection/Connection1.asp, line 18
kangbit
Mon 24 Aug 2009 16:46:24
มีข้อมูลเพิ่มเติมครับถ้าผมเปลี่ยนจาก Driver={sqldatabase}; เป็น DRIVER={MySQL ODBC 5.1 Driver} แล้วมีโค้ดดังด้านล่างนี้แล้วก็จะเกิด Error ดังนี้นะครับ
dim adoConn
dim adoRS
dim counter
set adoConn = Server.CreateObject("ADODB.Connection")
set adoRS = Server.CreateObject("ADODB.Recordset")
adoConn.Open "Driver={MySQL ODBC 5.1 Driver}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=mysql; Uid=root; Pwd=123456;"
adoRS.ActiveConnection = adoConn
if adoConn.errors.count = 0 then
response.write "<h2>Fields In The 'Contacts' Table:</h2>"
adoRS.Open "describe contacts"
while not adoRS.EOF
response.write adoRS.fields(0).value & "<br>"
adoRS.MoveNext
wend
else
response.write "ERROR: Couldn't connect to database"end i
-------------------------------------
Error Message
Error Type:
Active Server Pages, ASP 0115 (0x80004005)
A trappable error (C0000005) occurred in an external object. The script cannot continue running.
/TVCon_Reservation/Connection/Connection1.asp
kangbit
Tue 25 Aug 2009 11:12:30
ผมว่าทุกอย่างถูกหมดแล้วนะครับแต่ก็ยังมี Error ดังนี้ครับ
Active Server Pages, ASP 0115 (0x80004005)
A trappable error (C0000005) occurred in an external object. The script cannot continue running.
------------------------------------
โค้ดครับ
Dim Conn,Sql,Rs,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "mysql","root" , "123456"
strSQL = "SELECT * FROM help_category "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
While Not objRec.EOF
Response.write objRec.Fields("name").Value
objRec.MoveNext
Wend
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
ตามโค้ดด้านบนถ้าให้เหลือแต่
Dim Conn,Sql,Rs,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "mysql","root" , "123456"
strSQL = "SELECT * FROM help_category "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
ก็สามารถติดต่อฐานข้อมูลได้แต่ไม่สามารถดึงออกมาใช้งานได้นะครับ
kangbit
Wed 26 Aug 2009 09:32:11
ขอบคุณมากครับ ได้แล้วครับ
โค้ดที่เขียนมาถูกต้องแล้วครับแต่เป็นเพราะ ODBC connector 5.1 ไม่ support นะครับสงสัยต้องไปปรับแต่งอะไรอีกนิดหน่อยแต่ผมเอา 3.5 นี่แหละครับใช้ได้เหมือนกัน
webmaster
Wed 26 Aug 2009 11:58:16
ขอบคุณที่แจ้งครับท่านอื่นจะได้ทราบด้วย