Solved

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

Posted on 2008-09-30
7
725 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:mskitten
Comment Utility
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
Comment Utility
Something wrong with the connection string then...
0
 

Author Comment

by:mskitten
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Via a live example, show how to take different types of Oracle backups using RMAN.
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.

744 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

12 Experts available now in Live!

Get 1:1 Help Now