Trying to display data from an SQL database using vbscript

风流意气都作罢 提交于 2019-12-01 12:16:45
Ekkehard.Horner

Your

SQLConnection.provider = "ADODB.Connection"

is definitely wrong. As you specify the provider in the connection string, there is a (small) chance that deleting that line, will make your script 'work'.

UPDATE

(1) If you have problems connecting to your database, use this excellent source to get started on theory and samples, create an empty file (e.g. constr.udl), start it, and use the GUI to specify/test your connection. Leaving the dialog will save the connection string in the file, from where you can pick it up via a decent (Unicode enabled) editor.

(2) If you have too many errors on your ASP page, extract the (simplified) database code to a commandline .vbs script; that way you can focus on one foe (and deal with second one when you are sure, your SELECTs return the desired data).

(3) If you have problems with specific SQL statements/features/expressions, study the docs; in this case look into your favorite SQL book or follow Google to LIKE (according to the horse). JOIN may be a candidate too. Then use (2) to start from simple statements, proceed to more complex ones after you have mastered the seemingly boring. ("Table2.Date LIKE '2011'" may work or not, depending on the type and content of the Date column (and isn't Date a reserved/key word?)

(While Derek will surely read an answer to another of his question, other poeple starting here will probably profit from reading this too.)

Here's some example code for scripting ADO:

Set SQLConnection = CreateObject("ADODB.Connection")
SQLConnection.Open ConnectionString

Set rs = CreateObject("ADODB.RecordSet")
rs.Open "SELECT SYSTEM_USER AS Username, session_id, auth_scheme, net_transport, client_net_address FROM sys.dm_exec_connections WHERE (@@SPID = session_id)", SQLConnection 

' Loop through each record until there are no more
While NOT rs.EOF
    ' Loop through each field
    For Each field In rs.Fields
        output.Write field.Value & " "
    next

    rs.MoveNext
    output.WriteLine
Wend
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!