PROGRAMING/CLASSIC ASP

[ASP] ASP + MySQL Connection

donghunl 2011. 4. 5. 03:17
반응형

In order to connect to MySQL database from ASP you need to install MySQL ODBC connector. You can download the MySQL driver from the URL below

http://dev.mysql.com/downloads/connector/odbc/

1. Use System DSN

Open Data Sources(ODBC) and add System DNS



Dim adoConn

Set adoConn = Server.CreateObject(“ADODB.Connection”)
adoConn.Open “DSN=TestODBC;Uid=UserID;Pwd=Password;”

If adoConn.errors.count = 0 then
  Response.Write “Connected Successfully!”
Else
  Response.Write “Connection fail!”
End if

adoConn.close
Set adoConn = nothing


2. Use ODBC Driver



Dim adoConn

Set adoConn = Server.CreateObject(“ADODB.Connection”)
adoConn.Open “Driver={MySQL ODBC 5.1 driver}; Server=localhost; "&_
" Database=TestDB;Uid=UserID;Pwd=Password;”

If adoConn.errors.count = 0 then
  Response.Write “Connected Successfully!”
Else
  Response.Write “Connection fail!”
End if

adoConn.close
Set adoConn = nothing


반응형