thermionicvinyl
thermionicvinyl

Reputation: 3

Trouble opening connection to Oracle SQL in Visual Studio

I am currently developing an extremely basic app for entering the contact info of employees into an SQL database. I have no knowledge with regards to this kind of app development so I've been pulling together what I've found into something that works. I have successfully added a database connection through the server manager in Visual Studio but it looks like my test app crashes whenever I try to add/update any of the information. I tried connecting to a Microsoft SQL database instead and that worked fine. I've also tried stepping through the code and it seems to be failing to open the connection as it jumps straight to the catch exception statement.

public DataTable Select()
        {
            ///Step 1: Database Connection
            SqlConnection conn = new SqlConnection(myconnstrng);
            DataTable dt = new DataTable();
            try
            {
                //Step 2: Writing SQL Query
                string sql = "SELECT * FROM TBL_CONTACT";
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Creating SQL DataAdapter using cmd
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                conn.Open();
                adapter.Fill(dt);


            }
            catch (Exception ex)
            {

            }
            finally
            {
                conn.Close();
            }
            return dt;
        }

Upvotes: 0

Views: 269

Answers (1)

Eriawan Kusumawardhono
Eriawan Kusumawardhono

Reputation: 4896

You want to connect to Oracle DB, but you are using SqlConnection class. This is wrong, because SqlConnection is used to connect to SQL Server database, not for Oracle DB.

To connect to Oracle DB 12c or later (such as Oracle 18), use Oracle's ODAC (Data Access Component iibrary) instead.

For further reference: https://www.oracle.com/database/technologies/appdev/dotnet/odp.html

Upvotes: 1

Related Questions