Skip to Main Content

Oracle Developer Tools for Visual Studio

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I tell the OracleConnection to use the Hostname, Port and Service rather than the TNS alias?

ToolTimeTaborOct 6 2020 — edited Oct 7 2020

I am trying to connect to an Oracle XE instance using the ODP.NET managed driver.
image.pngYou can see here the using statement that references the client and the code at the point where the connection is instantiated and ready to be opened. You can see the connection string, but its components (Hostname, Port and Service) are empty. These are read-only properties, so I cannot set them. So, the connection string has to provide them.
image.png
I have two connections strings that work when I create them in Visual Studio under Project Properties settings.
DATA SOURCE=XE;PASSWORD=APX;USER ID=APX;PERSIST SECURITY INFO=True
DATA SOURCE=LOCALHOST:1521/XE;PASSWORD=APX;USER ID=APX;PERSIST SECURITY INFO=True
However, when I try to connect using a new connection object from the return value in the above function, as follows:
OracleConnection myConnection = myConnectionTools.ToOracle(connectionString)
myConnection.Open();
The first connection string (i.e. the TNS aliased connection) works, but I get this error for the second connection string.
image.pngThe connection string is valid. It works for Visual Studio.
How do I tell the OracleConnection to use the Hostname, Port and Service rather than the TNS alias?

This post has been answered by ToolTimeTabor on Oct 7 2020
Jump to Answer
Comments
Post Details
Added on Oct 6 2020
1 comment
480 views