Connecting to Oracle DB by IP

Joe-LC

New Member
Joined
Jun 14, 2012
Messages
2
Hi,

I am running Excel 2007 and connecting to an Oracle DB.

I have created a VBA macro to connect to an oracle DB and retrieve data then place it in a table. The code works, but it uses DSN entries which are specific to my computer. I want to be able to distribute this Excel spreadsheet to others in my company and have them be able to click one button and update the data. I figure the most logical way is to connect to the DB using an IP address that should work for anyone on the intranet.

How do I modify the connection info below to have it connect via IP?

I tried "Data Source = 10.1.1.10\orcl" and "Data Source = 10.1.1.10", both of which VBA dislikes.

Here is what I have now:

Code:
Sub Create()
    Dim Servername As Range
    Set Servername = ActiveWorkbook.Sheets("Summary").Range("B16")

    Set StartDate = ActiveWorkbook.Sheets("Summary").Range("B3")
    Set EndDate = ActiveWorkbook.Sheets("Summary").Range("B5")
    Set SearchUser = ActiveWorkbook.Sheets("Summary").Range("B19")
    Range("D2:H100").Clear
    
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
        "OLEDB;Provider=MSDASQL.1;Password=12345;Persist Security Info=True;User ID=ABCDE;Extended Properties=""DSN=" & Servername & ";UID=" & UserName & ";" _
        , "PWD=" & Password & ";"";Initial Catalog=(Default)"), Destination:=Range("$D$2")).QueryTable
        .CommandType = xlCmdSql
        
        .CommandText = Array( _
        "SELECT ... <edited out="">", _

        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False
        .ListObject.DisplayName = "Query"
        ActiveSheet.ListObjects("Query").TableStyle = "TableStyleMedium4"
        '
        ' Adds a 'Totals' row and sums the columns
        ActiveSheet.ListObjects("Query").ShowTotals = True
        ActiveSheet.ListObjects("Query").ListColumns("Burndown").TotalsCalculation = xlTotalsCalculationSum
        ActiveSheet.ListObjects("Query").ListColumns("Start").TotalsCalculation = xlTotalsCalculationSum
        ActiveSheet.ListObjects("Query").ListColumns("End").TotalsCalculation = xlTotalsCalculationSum
        ' Remove defaulted filter
        Range("Query[[#Headers],[End]]").Select
        Selection.AutoFilter
        ' Refreshes the query to align columns better
        ActiveWorkbook.RefreshAll

    End With

End Sub

Sub Refresh_Query()
'
' Button Click Macro
    ActiveWorkbook.RefreshAll
'
End Sub

Thanks a lot for taking a look!

Joe

</edited>
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Joe-LC

New Member
Joined
Jun 14, 2012
Messages
2
Anyone have any suggestions? Surely there must be a way to connect via IP.. If not, what about connecting via an entry in the tnsnames.ora file?
 

ChrisM

Well-known Member
Joined
Jun 11, 2002
Messages
2,129
You can do exactly this, I just no longer have my sample in front of me anymore to give you a perfect example sorry. Basically, go into the tnsnames file and find the full server address, ie "server.yourcompany.com port:1122"

Then in your connection string swap out the DSN entry for the full path.

from: http://www.codeproject.com/Articles/2304/ADO-Connection-Strings#ORACLE

strConnect = _T("Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;"
"Uid=MyUsername;Pwd=MyPassword;");

Hopefully that is enough to get you started.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,047
Messages
5,639,767
Members
417,110
Latest member
RayClarke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top