Connection to Oracle ODBC Datasource via Visual Studio asp.net

I would like to connect to a oracle db in our network, but I do not know how.
In visual code, we use this .env for our database connection:

# db credentials
ORACLEDB_USER=x
ORACLEDB_PASSWORD=x
ORACLEDB_HOSTNAME=xxxx
ORACLEDB_PORT=1521
ORACLEDB_SERVICE_NAME=xxxx
IF_INV_PATH=
inv_target_path=
TIFF_PATH_ROOT=
inv_path=

which works.
When I now try to use the Visual Studio ODBC Server connection I have to use a connection string.
I tried something like this (found via google):
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xxxx)));uid=xxxx;pwd=xxxx;

where I get this error:
Connection to Oracle ODBC Datasource via Visual Studio asp.net

(which loosely translates to: Datasource not found, and no default driver given)

I’m pretty confused and have no experience with setting up a connection to a oracle db.
I have installed the x64 driver from this site:
https://docs.microsoft.com/de-de/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15
But it doesn’t change anything.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Thanks to Wernfried Domscheit I finally got it to work.
Thanks man!
Here is how I did it:

  1. Install Visual Studio

  2. Download Version 18.5 Basic Package / ODBC Package

    https://www.oracle.com/de/database/technologies/instant-client/microsoft-windows-32-downloads.html

    https://www.oracle.com/de/database/technologies/instant-client/winx64-64-downloads.html#ic_winx64_inst

  3. unzip both in the same directory (I choose C:\oracle\odbc\x86(x64)\instantclient_18_5) and install the driver via cmd as admin: C:\oracle\odbc\x86\instantclient_18_5>odbc_install.exe

  4. create C:\oracle\admin and put tnsnames.ora in

    dev =
      (DESCRIPTION =
        (FAILOVER = ON)
        (LOAD_BALANCE = OFF)
        (CONNECT_TIMEOUT=3)
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = xxxxx)(PORT = 1521))
        )
        (CONNECT_DATA = 
          (SERVER = DEDICATED)
          (SERVICE_NAME = xxxxxx)
          (SID = ORCL)
        )
      )
    
  5. Systemvariables →
    Add TSN_ADMIN : C:\oracle\admin to the environment variables
    and C:\oracle\odbc to the path

  6. Open ODBC-Datenquelle-Adminsitrator 32 / 64 bit→ System-DSN and add

    Connection to Oracle ODBC Datasource via Visual Studio asp.net

  7. Open Visual Studio → Server Explorer → Connect to Database → Microsoft ODBC Data Source (ODBC) and choose your user / system data source name

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply