ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2003, 03:43 PM
swatch89 swatch89 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 swatch89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
using dynamic sql to get recordset from oracle

I need an asp code sample on how to execute a dynamic sql to get a recordset using Oracle as the data source. I am able to connect to the Oracle db using the connection string "Provider=MSDAORA;Data Source=<server name>;User ID=<user id>;Password=<password>;Database=<db name>;". I just need to use the correct syntax to build my SQL statement dynamically to get a recordset.

Reply With Quote
  #2  
Old November 21st, 2003, 03:53 PM
aardwulf's Avatar
aardwulf aardwulf is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 aardwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
These sites might help some. Haven't specifically used Oracle myself, but I do connection strings all the time...

Oracle connection strings
General connection string help

If you need to make it dynamic, that is easy enough, whatever the correct syntax is...

Code:
oConn.Open "Provider=" & yourProviderVariable & ";" & _
           "Data Source=" & yourDataSourceVariable & ";" & _ 
           "User Id=" & yourUserIDVariable & ";" & _
           "Password=" & yourPasswordVariable & ";"


Hope this helps some. Sorry I don't know Oracle specifically...

Reply With Quote
  #3  
Old November 21st, 2003, 07:26 PM
swatch89 swatch89 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 swatch89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry for the confusion, but what I actually need is how to create a dynamic SQL that will be executed by a command object after a connection to an Oracle database has been made.

*****************************************
Const CONNECT = "'Provider = MSDAORA; User ID=myuser; Password=mypwd;Data Source=myserver;DATABASE=mydb;"

Dim cn, rs, cmd, SQL

set cn = Server.CreateObject( "ADODB.Connection" )
set cmd = server.CreateObject ("ADODB.Command")
set rs = server.CreateObject ( "ADODB.Recordset" )

cn.Open CONNECT

SQL = "SELECT * FROM MyTable"
with cmd
set .ActiveConnection = cn
.CommandText = SQL
.CommandType = 1 'adCmdText
end with

set rs = cmd.execute

****************************************

What is the correct syntax for the variable SQL? I tried running this piece of code and it gave me an error "Operation is not allowed when the object is closed." I was able to successfully connect to the Oracle db, but not in executing the dynamic SQL in the command object.

Reply With Quote
  #4  
Old November 21st, 2003, 11:01 PM
unclefu unclefu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 120 unclefu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 57 sec
Reputation Power: 5
http://www.w3schools.com/ado/ado_ref_command.asp has information on the ADO Command object

also, since you've already got a recordset open you can just do

set rs = cn.execute(SQL) to have the results returned

Reply With Quote
  #5  
Old November 22nd, 2003, 09:08 AM
aardwulf's Avatar
aardwulf aardwulf is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 aardwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have never used the "Command" variable type. I just do something like the following:

Code:
Dim cn, rs, queryString

cn = Server.CreateObject("ADODB.Connection")
rs = Server.CreateObject("ADODB.Recordset")

cn.Open "Provider = MSDAORA; User ID=myuser; " & _
   "Password=mypwd;Data Source=myserver;DATABASE=mydb"

queryString = "SELECT * FROM MyTable WHERE " &
   "param1 = " & mVar & " AND " & _
   "param2 = " & myOtherVar

rs.Open queryString, cn


Hope this helps somewhat.

Chris

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > using dynamic sql to get recordset from oracle


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT