Re: Simple SQL Connection



On Jul 31, 10:03 am, Rem-8 <lukasz.r...@xxxxxxxxx> wrote:
Hello

I'm a new to VBS and searched sites for vbs script but non of them
worked. I'm looking for a script which will create a connection to the
database, do a select on a table and then output it in command line.
Many thanks for the reply.

Regards

Hi. You really really should be asking your question in a vb script
newsgroup. A good one is microsoft.public.scripting.vbscript.

However, since I know the answer I'll go ahead and post it. :)

The following will so what you want if you save it in a vbs file and
run it from a command prompt. Of course, change the obvious stuff
like the database name, server and table name. This should get you
started.

Dim cn
Dim rs

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.ConnectionString = "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"User ID=sa;" & _
"pwd=xxx;" & _
"Initial Catalog=Database;" & _
"Data Source=Server"
cn.CommandTimeout = 180

cn.Open
sQry = "Select * from Table"

rs.Open sQry, cn

Do until rs.eof
wscript.echo rs(0).value & " " & rs(1).value
rs.movenext
Loop

.



Relevant Pages

  • Re: Thoughts on current error handling best practice with VBScript
    ... Anthony Jones also recommends not using VBS if you're concerned about ... Dim sVal ... impression about how much of an afterthought error handling has been ... you've run the script from an open command window, using cscript, Ctrl- ...
    (microsoft.public.scripting.vbscript)
  • Re: Questions about GetRef() and ASP, etc.
    ... > stack does NOT extend into a called procedure's scope. ... > script requires catch-all error handling, however, it is often best to set ... > unexposed functions, mix VBS and JS, etc. WSCs are fairly well documented ... > The Err object appears to be misdocumented in the MS VBS documentation. ...
    (microsoft.public.scripting.vbscript)
  • Re: Help with values for Error Trapping
    ... The point of a script like VBS is to use many different ... The Err object is an intrinsic global object available under all hosts. ... is error-trapping status in effect at any level in the stack. ...
    (microsoft.public.scripting.vbscript)
  • Re: Help with values for Error Trapping
    ... The point of a script like VBS is to use many different ... >The Err object is an intrinsic global object available under all hosts. ... >is error-trapping status in effect at any level in the stack. ...
    (microsoft.public.scripting.vbscript)
  • Re: An executable file to run a VB script?
    ... do directly from VBA and what does Excel offer that you couldn't do entirely ... with a vbs script? ... of the script host. ... mode and wscript.exe will run vbs files with the windows user ...
    (microsoft.public.excel.programming)

Loading