Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Oracle service
How to connect to oracle database in windows service?
I want to access say temp database and emp table from it.
username=xyz
pwd=abcd
 
suggest the solution with select query.
Posted 28-Apr-13 21:27pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Download & Install Oracle Data Provider for Net[^]. Use code similar to one shown below to connect to Oracle & Retrieve the data.
string strPass;
string strCon = "USER_NAME/PASSWORD@//DB_SERVER_HOST_OR_IP:PORT/SERVICE_NAME";
using (OracleConnection conn = new OracleConnection(strCon))
{
    conn.Open();
    using (OracleCommand cmd = new OracleCommand())
    {
        cmd.Connection = conn;
        cmd.CommandText = "SELECT * FROM emp_table WHERE username = :userId";
        cmd.CommandType = CommandType.Text;
        OracleParameter pUser = new OracleParameter();
        pUser.OracleDbType = OracleDbType.Varchar2;
        pUser.Value = "xyz";
        cmd.Parameters.Add(pUser);
        using (OracleDataReader dr = cmd.ExecuteReader())
        {
            dr.Read();
            //strPass = dr["pwd"].ToString();
            strPass = dr.GetOracleString(1)); // Assuming that the pwd is a second column.
        }
    }
}
Regards,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100