Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Can I access database from VBScript.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,23865
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Can I access database from VBScript.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Can I access database from VBScript. - 7/20/2005 7:01:06 PM   
  deepujain

 

Posts: 2
Score: 0
Joined: 7/20/2005
Status: offline
Hi folks,
  I am new to vb script. Can i access database{.mdb} from a vb script. All I need to do  is connect to mdb and read a row from a table and check for a specific condition and send a mail if its true. I want to do this daily. Now I was able to make the script run daily and even send mail. But i am not able to access the database.  Can anyone help me on this issue.

Thanks , Awaiting for ur reply.
 
 
Post #: 1
 
 RE: Can I access database from VBScript. - 7/20/2005 10:05:35 PM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi deepujain,

you asked your question in the "test section" of this forum. So I'm not sure, whether you
really need an answer.

Because I'm interested in database work, I would like to help you. So I just put your question
to the VBScript section, if possible adding some info (filename of your .mdb, SELECT statement).
I will try to come up with a proof of concept script.

Now if I read my post again - perhaps you are doing it just now? That would make look this
posting kind of silly.

(in reply to deepujain)
 
 
Post #: 2
 
 RE: Can I access database from VBScript. - 7/21/2005 9:53:37 PM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Bare bones script to access existing .mdb:

Const adOpenForwardOnly = 0
Const adLockReadOnly    = 1
Const adCmdText         = 1
Dim sVers
Dim sFSpec
Dim sSQL
' Change this according to your specific situation/environment/needs
sVers  = "Microsoft.Jet.OLEDB.4.0" ' "Microsoft.Jet.OLEDB.3.51"
sFSpec = ".\forum.mdb"
sSQL   = "SELECT sActivity FROM Activity WHERE sActivity = 'one'"
' sSQL   = "SELECT sActivity FROM Activity WHERE sActivity = 'eins'"
Dim oFS
Dim oCNCT
Dim oRS
Dim sTmp
Set oFS   = CreateObject( "Scripting.FileSystemObject" )
sFSpec    = oFS.GetAbsolutePathName( sFSpec )
Set oCNCT = CreateObject( "ADODB.Connection" )
Set oRS   = CreateObject( "ADODB.Recordset" )
sTmp      = "Provider=" + sVers + ";" + "Data Source=" + sFSpec + ";"
oCNCT.Open sTmp
oRS.Open sSQL, oCNCT, adOpenForwardOnly, adLockReadOnly, adCmdText
If oRS.BOF Or oRS.EOF Then
    WScript.Echo "Not found"
Else
    WScript.Echo "found: " & oRS.Fields( "sActivity" ).Value
End If
oRS.Close
Set oRS   = Nothing
oCNCT.Close
Set oCNCT = Nothing
Set oFS   = Nothing

(in reply to deepujain)
 
 
Post #: 3
 
 RE: Can I access database from VBScript. - 7/22/2005 4:24:19 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
ehvbs, I'm also mildly interested in using scripting (not necessarily limited to vbscript) to access databases, although I dont have a specific work application, just mainly interested in ways to use VB 6 (haven't started learning VB.NET yet) ADO engines within scripts to access data. You know of anyone or anyplace doing something like that, or do most people just use SQL calls directly within scripts? thanks

(in reply to deepujain)
 
 
Post #: 4
 
 RE: Can I access database from VBScript. - 7/22/2005 4:32:01 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
SQL is widely used and pretty easy to maintain, aswell as it's cross compatibility...

=)

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to marcusrp)
 
 
Post #: 5
 
 RE: Can I access database from VBScript. - 7/22/2005 5:06:58 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi marcusrp,

knowing next to nothing about VB 6, I'm afraid I can't help you there. But I believe that
the common "Visiual Basic" base of VBS, VBA, and VB makes it worthwhile to look for
samples/applications/solutions in all three spheres. So if googleing for
   "ado database vb6 ..."
fails, I'd definitely try
   "ado database access ..."
and I'd like to hear, whether my sample code could be ported to VB.

(in reply to Snipah)
 
 
Post #: 6
 
 RE: Can I access database from VBScript. - 7/22/2005 9:12:01 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
thats actually not a bad idea...the code you posted right here might make a perfect (e.g. SMALL) example...I'll work on it and let you know what I come up with...

(in reply to deepujain)
 
 
Post #: 7
 
 RE: Can I access database from VBScript. - 7/23/2005 3:18:15 PM   
  TNO


Posts: 1241
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: online
w3schools has an excellent tutorial:

http://www.w3schools.com/ado/default.asp

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to marcusrp)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Can I access database from VBScript. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts