Solved

vbscript to connect to access db

Posted on 2004-09-10
6
417 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
Comment Utility
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
Comment Utility
Leon,

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

Expert Comment

by:leonstryker
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:barryk2
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now