?
Solved

vbscript to connect to access db

Posted on 2004-09-10
6
Medium Priority
?
429 Views
Last Modified: 2013-12-25
Hello I am wondering if it is possible to connect to a db and perform operations froma standalone vbscript.  I typically run these vbs files from the command line and it seems this is possible but everythings I have tried in my code does not work. I have used asp and vbscript to connect to access or sql server databases.  I have created an odbc link to a db but thats about as far as I have gotten.
0
Comment
Question by:barryk2
6 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 12030667
Here is an ADO tutorial which shows how it works from ASP (using VBS)

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

Here is where you will find your connection strings:

http://www.able-consulting.com/ADO_Conn.htm

Leon
0
 

Author Comment

by:barryk2
ID: 12030702
Leon,

I  really was looking for some code that is straight vbs no asp or server.
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 12030976
Try this:

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select Count(*) From Customers", conn
MsgBox "Where are " & rs(0).Value & " records in the table"

Leon

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:barryk2
ID: 12031208
Ran your code:

VBScript Runtime Error: Object Required: 'Server'

I have used similar code when connecting to db's through asp & vbscript but just running vbscript alone I cannot seem to find what to put in the place of Server.CreateObject etc...


Any Ideas?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 12031578
You just need CreateObject("ADODB.Connection").  Obviously Server.CreateObject makes no sense, cos the scripting runtime doesn't know what a Server is.

Hope this helps.
0
 
LVL 10

Expert Comment

by:anv
ID: 12033920
though carl_tawn has given the answer

still for further reference u can chek this link

http://www.experts-exchange.com/Programming/Q_20643048.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question