Wednesday, April 02, 2008

Tips For Running ASP Code On Linux

Yesterday, I worked on an i2x project that involved porting a small ASP application over to a Linux box. Here's some tips I learned along the way:

  • What do you know, you can run ASP on Linux! Who knew? Well, my customer did, or they wouldn't have suggested it. The magic is provided by Chilisoft, a SUN product believe it or not.
  • Chilisoft knows about various VB style objects, so you can say:
     Set conn = Server.CreateObject("ADODB.Connection") 
     Set rs   = Server.CreateObject("ADODB.RecordSet")
  • While Chilisoft supports database access, it does not support MS Access. If you do:
     Set conn = Server.CreateObject("ADODB.Connection") 
     conn.Open Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
                        & Server.MapPath("foo.mdb")
    You'll get an incomprehensible error message - something along the lines of:
    ADODB.Connection (0x800A0BB9)
    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
    Which is just a cryptic way of saying: Dude, you're on a Linux box, you can't run MS Access stuff here. What were you thinking?
  • One way to deal with the fact that Chilisoft doesn't do MS Access is to convert your database to MySQL. Chilisoft gets along just fine with MySQL. To do this, you should not, as I attempted to do, manually export files from Access and try to manually import them into MySQL. Instead, use the near magical migration toolkit, which is provided by MySQL. It will slurp in your MS Access .mdb file and produce a populated MySQL database. It's awesome.
  • To connect to a MySQL database from Chilisoft, you want to use the connection string:
     Set conn = Server.CreateObject("ADODB.Connection")
     conn.Open "Driver={Mysql}; Server=<host>; Database=<db name>; UID=<username>; PWD=<password>"
  • You can't use the CDO.Message object to send mail in Chilisoft, as the object isn't available. But take heart, the CDONTS.NewMail object is. See this discussion for how to use it. Luckily, it boils down to:
     Dim MyEmail
     Set MyEmail = Server.CreateObject("CDONTS.NewMail")
     MyEmail.Subject = "testing"
     MyEmail.Body = "test message"
     MyEmail.From = "some email address you set up from your own domain" 
     MyEmail.To = ""

Happy ASP hacking!

No comments:

Post a Comment