Re: Simple SQL Connection
- From: Jennifer <J.Evans.1970@xxxxxxxxx>
- Date: Tue, 31 Jul 2007 12:10:37 -0700
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
.
- References:
- Simple SQL Connection
- From: Rem-8
- Simple SQL Connection
- Prev by Date: Re: How to avoid that a key can be hold down
- Previous by thread: Simple SQL Connection
- Index(es):
Relevant Pages
|
Loading