PC Review


Reply
Thread Tools Rate Thread

Accessing Data from an oracle database on a different server using

 
 
Rohan Pradhan
Guest
Posts: n/a
 
      12th Aug 2008
Hi ,
I want to extract data from an oracle database and display it in an Excel
worksheet . I am not a regular programmer and do not know how to go about
with it. Can someone please help me out. Thanks in advance

 
Reply With Quote
 
 
 
 
NateBuckley
Guest
Posts: n/a
 
      12th Aug 2008
First you will need to set up a reference to the various objects that you
will need to use to make the connection.

Go to Macro Editing Screen (Visual Basic Editor) from Excel, alternativly
press Alt+F11 then go to Tools - References and Check "Microsoft ActiveX data
Object 2.8 Library" and click ok. (you may have a different version but one
of the higher numbers should do)

Now you can connect to an Oracle database with the following code
Sub ConnectToDB()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim dbPath as String

dbPath = "C:\db\db.db" 'Unsure if thats the extension for oracle
Set con = New ADODB.Connection
con.Provider = "msdaora"
con.Open "Data source=" & dbPath & ";User ID=test;Password=pwd;"

strSQL = "SELECT * FROM tblEmployees"

Set rs = New ADODB.Recordset
rst.Open strSQL, con, adOpenDynamic, adLockReadOnly

While Not rs.eof
MsgBox rs.fields!EmployeeName
Wend

rs.close
con.close

Set rs = Nothing
Set con = Nothing
End Sub

You'll need to learn some SQL statements to extract more information from
your database, but it's really easy and you'll be doing complex db
interactions in no time.

I haven't tested this as I don't have access to Oracle here, but I'm quite
sure thats hwo I did it at home. (at work)
"Rohan Pradhan" wrote:

> Hi ,
> I want to extract data from an oracle database and display it in an Excel
> worksheet . I am not a regular programmer and do not know how to go about
> with it. Can someone please help me out. Thanks in advance
>

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      13th Aug 2008
Just to add to Nate's post - don't forget you'll need the Oracle Client
package installed on any machine you want to run this on.

This:

dbPath = "C:\db\db.db"

will instead look something like:

dbPath = "myDBName"

...since you're accessing a DB on a remote server. "myDBName" will be the
name defined in your [local] tns_names.ora file (basically a "lookup" file
for remote database instances which maps "names" to server details). Ask
your DBA if you need assistance with this.

Tim

"NateBuckley" <(E-Mail Removed)> wrote in message
news:464F182B-C528-46F6-BE42-(E-Mail Removed)...
> First you will need to set up a reference to the various objects that you
> will need to use to make the connection.
>
> Go to Macro Editing Screen (Visual Basic Editor) from Excel, alternativly
> press Alt+F11 then go to Tools - References and Check "Microsoft ActiveX
> data
> Object 2.8 Library" and click ok. (you may have a different version but
> one
> of the higher numbers should do)
>
> Now you can connect to an Oracle database with the following code
> Sub ConnectToDB()
> Dim con As ADODB.Connection
> Dim rs As ADODB.Recordset
> Dim strSQL As String
> Dim dbPath as String
>
> dbPath = "C:\db\db.db" 'Unsure if thats the extension for oracle
> Set con = New ADODB.Connection
> con.Provider = "msdaora"
> con.Open "Data source=" & dbPath & ";User ID=test;Password=pwd;"
>
> strSQL = "SELECT * FROM tblEmployees"
>
> Set rs = New ADODB.Recordset
> rst.Open strSQL, con, adOpenDynamic, adLockReadOnly
>
> While Not rs.eof
> MsgBox rs.fields!EmployeeName
> Wend
>
> rs.close
> con.close
>
> Set rs = Nothing
> Set con = Nothing
> End Sub
>
> You'll need to learn some SQL statements to extract more information from
> your database, but it's really easy and you'll be doing complex db
> interactions in no time.
>
> I haven't tested this as I don't have access to Oracle here, but I'm quite
> sure thats hwo I did it at home. (at work)
> "Rohan Pradhan" wrote:
>
>> Hi ,
>> I want to extract data from an oracle database and display it in an Excel
>> worksheet . I am not a regular programmer and do not know how to go about
>> with it. Can someone please help me out. Thanks in advance
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
50 concurrent web users on asp.net 2.0 accessing Oracle database jobs Microsoft ASP .NET 2 19th Jun 2007 06:08 PM
Searching for a simple (!) sample for accessing an Oracle database and read some data from it Ken Williams Microsoft C# .NET 2 24th May 2007 07:01 PM
Accessing an Oracle database with vb.net Mark Brown Microsoft VB .NET 2 27th Feb 2007 02:47 PM
Data provider for CF2.0, SQL Mobile to an Oracle database server? Kimberly Microsoft Dot NET Compact Framework 1 11th Aug 2005 04:46 PM
Accessing Oracle Database Arun Microsoft ADO .NET 4 21st May 2005 01:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 PM.