Tuesday, March 27, 2012

access db using vbscript?

Is it possible to access a msde db using vbscripting?
Thanks
Andres
If you mean from an ASP page, yes. But I don't think it is possible from a
vbscript within an HTML page.
"Andres" wrote:

> Is it possible to access a msde db using vbscripting?
> Thanks
> Andres
>
|||Arnar Tór Guemundsson wrote:[vbcol=seagreen]
> If you mean from an ASP page, yes. But I don't think it is possible from a
> vbscript within an HTML page.
> "Andres" wrote:
>
How to access MSDE from ASP or plain vbscript run from command line.?
Please show both if possible.
Thanks
Andres
|||hi Andres,
Andres wrote:
> How to access MSDE from ASP or plain vbscript run from command line.?
> Please show both if possible.
>
for ASP you have to use a web server (IIS, Cassini, ..) but via vbscript you
can use the ADO object model...
for instance you can connect to the local default instance of MSDE using a
trusted connection, opening the "pubs" sample database and open a recordeset
to iterate throught the [authors] table selecting the au_id, au_lname and
au_fname columns and show the result of this concatenation in a
messagebox...
something like
<-- file.vbs -->
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdText = 1
Const adStateClosed = 0
Dim myErr
Dim oCon
Dim oRs
Dim myStr
Dim iLoop
Set oCon = CreateObject("ADODB.Connection")
oCon.ConnectionString = "Provider=sqloledb;Data Source=(Local);Initial
Catalog=pubs;Integrated Security=SSPI;"
ON ERROR RESUME NEXT
oCon.Open
myErr = Err.description
ON ERROR GOTO 0
If myErr = "" Then
Set oRs = CreateObject("ADODB.RecordSet")
ON ERROR RESUME NEXT
oRs.Open "SELECT au_id, au_lname, au_fname FROM [authors]" , oCon,
adOpenForwardOnly, adLockReadOnly, adCmdText
myErr = Err.description
ON ERROR GOTO 0
If myErr = "" Then
If oRs.State = adStateClosed Then myErr = "Error"
End If
If myErr = "" Then
For iLoop = 0 To oRs.Fields.Count - 1
myStr = myStr + oRs.Fields(iLoop).Name + " "
Next
myStr = myStr + VbCrLf
While not oRs.Eof
'myStr = ""
For iLoop = 0 To oRs.Fields.Count - 1
myStr = myStr + oRs.Fields(iLoop).Value + " "
Next
myStr = myStr + VbCrLf
oRs.MoveNext
Wend
MsgBox myStr
End If
Set oRs = Nothing
End If
Set oCon = Nothing
<-->
then it really depends on your needs..
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.15.0 - DbaMgr ver 0.60.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

No comments:

Post a Comment