Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-09-30
7
Medium Priority
?
749 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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ā€¦
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

618 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