0

I am trying to connect to Oracle database on my local machine. I have Visual Studio 2013 and Oracle Express 11g.

Here's my c# code:

    String str =
        "Data Source=localhost;" +
        "Initial Catalog=XE;" +
        "User Id=system;" +
        "Password=12345;";
        SqlConnection conn = new SqlConnection(str);
        conn.Open();

However it throws an exception:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: 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

Does anybody know what's going wrong?

2
  • Shouldn't you be using an Oracle provider? Commented Jul 28, 2015 at 16:08
  • 2
    SqlConnection is the SQL Server specific provider - it doesn't work with Oracle ... Commented Jul 28, 2015 at 16:09

2 Answers 2

1

Check your provider, as I commented above....

Taken from Oracle Web Site...

string oradb = "Data Source=(DESCRIPTION="
             + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ORASRVR)(PORT=1521)))"
             + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));"
             + "User Id=***;Password=***;";

OracleConnection conn = new OracleConnection(); 
conn.ConnectionString = oradb;
conn.Open();

You may want to look at ConnectionStrings.com to help with which suits you best.

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

Comments

0

The problem is that you're trying to use the classes in the System.Data.SqlClient namespace with Oracle. SqlClient is only for Sql Server. You need to use either an Oracle .Net provider or the classes in the System.Data.OleDb namespace.

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.