Solved

vbscript to connect to access db

Posted on 2004-09-10
6
419 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

867 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

15 Experts available now in Live!

Get 1:1 Help Now