Solved

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

Posted on 2008-09-30
7
732 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

749 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