Sql-server – VBScript/ASP Classic

asp-classicmodel-view-controllersql servervbscript

I have a couple of questions regarding VBScript and ASP Classic:

  1. What is the preferred way to access an MS SQL Server database in VBScript/ASP?

  2. What are best practices in regards to separating model from view from controller?

  3. Any other things I should know about either VBScript or ASP?

If you haven't noticed, I'm new at VBScript coding. I realize numbers 2 & 3 are kind of giant "black hole" questions that are overly general, so don't think that I'm expecting to learn everything there is to know about those two questions from here.

Best Answer

ADO is an excellent way to access a database in VBScript/Classic ASP.

Dim db: Set db = Server.CreateObject("ADODB.Connection")
db.Open "yourconnectionstring -> see connectionstrings.com"
Dim rs: Set rs = db.Execute("SELECT firstName from Employees")
While Not rs.EOF
    Response.Write rs("firstName")
    rs.MoveNext
Wend
rs.Close

More info here: http://www.technowledgebase.com/2007/06/12/vbscript-how-to-create-an-ado-connection-and-run-a-query/

One caveat is that if you are returning a MEMO field in a recordset, be sure you only select ONE MEMO field at a time, and make sure it is the LAST column in your query. Otherwise you will run into problems. (Reference: http://lists.evolt.org/archive/Week-of-Mon-20040329/157305.html )