1

I try to connect to an OracleDB from an c# project.

SqlConnection thisConnection = new SqlConnection(
"Server=127.0.0.1:3306;Database=db1;User id=abc;Password=psw;");

While running the code an exeption is thrown:

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

I tried to connect with an local mysql db either and the same exeption is thrown.
I can connect to the server with the Oracle SQL developer tool.

Where is the Problem ?

1
  • 1
    OracleDB using SqlConnection ???. You know SqlConnection is for SQL Server Commented Jul 9, 2014 at 14:23

4 Answers 4

2

You are using a SqlConnection (SQL Server) to connect to an Oracle database. See this answer on how to connect to an Oracle database:

https://stackoverflow.com/a/12568350/2382032

As Flindeberg points out, here is the NuGet link:

https://www.nuget.org/packages/odp.net.managed/

Sign up to request clarification or add additional context in comments.

4 Comments

Eh, no, that is the unmanaged driver, don't use that one. Since about a year back they have a managed driver (ie .NET).
The answer I link to has a link to the same place as your answer, oracle.com/technetwork/topics/dotnet/index-085163.html. Thanks though, I will update my answer with the nuget link. I wish they had NuGet back in the day when I had to connect to Oracel!
Now I can connect to the server but the login fails. Do I have to surround the pasword with special chars or does it work like this: "User ID=username;Password=asd;....."?
Every example I see here does not surround it with quotes: connectionstrings.com/oracle
1

You are using SqlConnection class. This class is used to connect to Microsoft's SQL Server database.

Since the database you're making use of is Oracle's database, you'll need a 'Oracle' specific connection class.

You can make use of OracleDBConnection class though this is not advisable as it has been deprecated.

Instead, you can make use of ODP.NET which is provided & supported by Oracle.

Hope this helps!!!

3 Comments

Note this method of connecting has been depreciated: msdn.microsoft.com/en-us/library/77d8yct7.aspx
System.Data.oracleClient has been deprecated
Thanks for pointing that out. I had forgotten it had been deprecated. Have edited my answer accordingly!!!
0

You are using the connector for MS SQL server, don't do that. The only driver you should use for the Oracle Managed ODP.NET driver which you can get at NuGet. Documentation is available here.

Make sure to use the managed driver, and not the unmanaged one.

Example of using it:

var connection = new OracleConnection(str);
using (var command = new OracleCommand(commandStr, connection))
{
   // do stuff with command
}

Comments

0

Try using ODP.Net Driver from NuGet.

Follow the instruction here:
Connect to oracle from c#

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.