• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

Connecting to Oracle

Hi,

I am trying to learn ASP.Net, but I have been unable to connect and return records from an Oracle database.  I have Oracle connection string which I use with ADO and VB.

DB_Connect = "Provider=MSDAORA.1;Password=project;User ID=project;Data Source=ext5.world"

Thanks for any help

Damien.
0
damienm
Asked:
damienm
  • 3
1 Solution
 
AerosSagaCommented:
         o



#  Oracle

    *  ODBC


          o  New version:
            "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;"


          o  Old version:
            "Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;"


    *  OLE DB, OleDbConnection (.NET)


          o  Standard security:
            "Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Password=asdasd;"

                This one's from Microsoft, the following are from Oracle

          o  Standard Security:
            "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;"


          o  Trusted Connection:
            "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;"


    *  OracleConnection (.NET)


          o  Standard:
            "Data Source=Oracle8i;Integrated Security=yes;"

                This one works only with Oracle 8i release 3 or later

          o  Specifying username and password:
            "Data Source=Oracle8i;User Id=username;Password=passwd;Integrated Security=no;"

                This one works only with Oracle 8i release 3 or later

          o  Declare the OracleConnection:

                C#:
                using System.Data.OracleClient;
                OracleConnection oOracleConn = new OracleConnection();
                oOracleConn.ConnectionString = "my connectionstring";
                oOracleConn.Open();



                VB.NET:
                Imports System.Data.OracleClient
                Dim oOracleConn As OracleConnection = New OracleConnection()
                oOracleConn.ConnectionString = "my connectionstring"
                oOracleConn.Open()

    *  Core Labs OraDirect (.NET)


          o  Standard:
            "User ID=scott; Password=tiger; Host=ora; Pooling=true; Min Pool Size=0;Max Pool Size=100; Connection Lifetime=0"

                Read more at Core Lab and the product page.

    *  Data Shape


          o  MS Data Shape:
            "Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA;Data Source=orac;user id=username;password=mypw"

                Want to learn data shaping? Check out 4GuyfFromRolla's great article about Data Shaping >>

http://www.connectionstrings.com/

Any error message would also be helpful.

Regards,

Aeros
0
 
damienmAuthor Commented:
Hi,

I need more than the connection string code, I don't know asp.net very well at all, so some sample code which outputs something to the screen from a table in Oracle would be good.

Damien
0
 
AerosSagaCommented:
outputting to a screen will be the same no matter what.  You will need to decide which provider you will be using for your connection from above and then your code will look something like this.  You will just swap out where it says sql client with your oracle provider of choice:
***The astricks are the parts you will need to change once you decide on your provider
 Private Sub LoadProductData()
        Dim cnn As New ByteFX.Data.MySqlClient.MySqlConnection(ConfigurationSettings.AppSettings("SiteDB")) ****
        Dim cmd As New ByteFX.Data.MySqlClient.MySqlCommand*****
        Dim dr As ByteFX.Data.MySqlClient.MySqlDataReader******
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "SELECT * FROM CustomerTracking WHERE SessionID = '" & Me.lblTrackingID.Text.ToString & "'"
        cmd.Connection = cnn
        cnn.Open()
        dgCart.DataSource = cmd.ExecuteReader
        dgCart.DataBind()
        cnn.Close()
        cmd.Dispose()
        cnn.Dispose()
    End Sub
0
 
AerosSagaCommented:
your connection string goes in your web.config file like so:

<appSettings>
<add key="SiteDB" value="Persist Security Info=False;database=MyDB;server=63.XXX.XX.XX;user id=root;pwd=XX"></add>
      </appSettings>
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now