Solved

How do I execute an sql query using a vbscript inputbox?

Posted on 2008-09-30
7
731 Views
Last Modified: 2013-12-18
How would I go about creating a vbscript that asks the user for a username, then when entered, it runs the following sql query:

             select username, granted_role
             from   all_users a,
             dba_role_privs b
             where  a.username = b.grantee
             and   ( b.granted_role like 'WV%'
             or b.granted_role like 'SV%')
             and a.username = UPPER('&1');

The query is searching to see if a user has a specific Oracle role, so if the user does have a role (beginning with WV, or SV), a dialogue will popup and say "user has the following roles" and then list the associated roles.

I have NO idea how to do this, but it is something that I'd really like. I imagine there would need to be a connection string involved, which is WV_PROD with a schema owner of PROD1 and password pf PROD1.

I hope what I'm asking for makes sense. Thanks in advance to those who can help!!    
0
Comment
Question by:mskitten
  • 3
  • 3
7 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 22610707
This should work for you...
Dim con : Set con = CreateObject("ADODB.Connection")
con.Open "Provider=SQLOLEDB.1;Initial Catalog=WV_PROD","PROD1","PROD1"
 
strUser = InputBox ("Enter user name:")
strSQL="select username, granted_role from all_users a, dba_role_privs b where a.username = b.grantee and (b.granted_role like 'WV%'              or b.granted_role like 'SV%') and a.username = UPPER('" & strUser & "');
 
Dim objRS : set objRS=con.execute(strSQL)
If objRS.EOF Then
  wscript.echo "No records found"
Else
  Wscript.echo "user has the following roles:"
  Do While Not objRS.EOF
    wscript.echo objRS.Fields(1)
    objRS.MoveNext
  Loop
End If
objRS.Close

Open in new window

0
 

Author Comment

by:mskitten
ID: 22619750
I am getting an Unterminated string constant error on the 5th line. I'm thinking there is a problem with this part:
and a.username = UPPER('" & strUser & "');

I tried adding a quote on the end, but it seemed that didn't work for me. After taking that part out, I now get this error (see attached). I'm thinking the provider or connection?

This is some connection info that we use in scheduled task. Maybe it will help.
 /opendb=provider=msdaora;data source=wv_prod;password=prod1;user id=prod1;
dberror.JPG
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22620299
strSQL="select username, granted_role from all_users a, dba_role_privs b where a.username = b.grantee and (b.granted_role like 'WV%'              or b.granted_role like 'SV%') and a.username = UPPER('" & strUser & "');"

What do you get with the quote on the end?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:mskitten
ID: 22625627
I might have been mistaken with the quote it looks like (long day yesterday).

I now get this error. See attached.
dberror2.JPG
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 500 total points
ID: 22625760
Something wrong with the connection string then...
0
 

Author Comment

by:mskitten
ID: 22670647
Hello, sorry for they delay. I've been waiting for the connection string info. I'll let you know once they have gotten back to me.

Thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

809 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