Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Script to test an ODBC connection?

Posted on 2006-04-24
5
Medium Priority
?
1,357 Views
Last Modified: 2012-06-27
I am not sure if this is the right place to ask but here goes:

I have a user who manually setup a System DSN  ODBC connection for SQL 2000.

I can only as for a name of that connection such as "ODBC_SQL", this name is the DSN configuration for SQL 2000 that he allready stated the server, the user name and password and which database to connect to in the setting.

He is running window 2000.
I know the driver he use is " sun.jdbc.odbc.JdbcOdbcDriver",
I am unsure but the URL can be "jdbc:odbc:ODBC_SQL "

Is there a vb script that I can use to connect to his datbase to test if certain table exists? so that when I run the script, if the table exists then I get a pop up message saying good connection, else saying bad connection?
0
Comment
Question by:fylix0000
5 Comments
 
LVL 4

Assisted Solution

by:g_johnson
g_johnson earned 1050 total points
ID: 16528530
dim c1 as adodb.connection
dim rs1 = adodb.recordset

set c1 = new adodb.connection
c1.connectionstring = "ODBC=ODBC_SQL"
c1.open

set rs1 = new adodb.recordset
set rs1.activeconnnection = c1

on error goto errTrap:
rs1.open "SELECT 'Y' FROM table_name"
'no problem with table or connection
rs1.close

ExitHere:
   set rs1.activeconnection = nothing
   set rs1 = nothing

   c1.close
   set c1 = nothing

ErrTrap:
    'problem with table or connection


does that help?

0
 

Author Comment

by:fylix0000
ID: 16528728
I save it as test.vbs and run but got the error

Line: 1
Char: 8
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error.

Sorry if I sound clueless because I am :)
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16532006
>>Dim rs1=adodb.recordset

it should be
 dim rs as adodb.recordset
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16533393
if you use vbscript

you need to declare as just

dim rs

ie

dim c1 as adodb.connection

set c1 = wscript.createobject("adodb.connection")
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 450 total points
ID: 16533395
dim c1
set c1 = wscript.createobject("adodb.connection")
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

581 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