creating connections to oracle databases

Upload: sourav-riya

Post on 05-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Creating Connections to Oracle Databases

    1/3

    5/12 Creating Connections to Oracle Databases

    dn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx

    8 out of 20 rated this helpful - Rate this topic

    Creating Connections to Oracle DatabasesVisual Studio .NET 2003

    When connecting to an Oracle database use the Microsoft OLE DB Provider for Oracle .

    Note To enable drag and drop support from Server Explorer for Oracle databases,

    the data connection must use the Microsoft OLE DB Provider for Oracle.

    Security Note Storing connection-string details (such as the server name, user name,and password) can have implications for the security of your application. UsingWindows Integrated Security is a more secure way to control access to a database.For more information, see Database Security .

    There are two ways to connect to an Oracle database:

    Visually, with design-time tools.Programmatically.

    Connecting to an Oracle Database in Server ExplorerTo create a connection in Server Explorer

    1. In Server Explorer, right-click Data Connections and click Add Connection .2. In the Data Link Properties dialog box, click the Provider tab.3. Click the Microsoft OLE DB Provider for Oracle , then click Next .4. Type the server where the database you want to access is located.5. Type the password to use for authentication when you log on to the data source.6. Click OK .

    Connecting to an Oracle Database from within your applicationCreating connections to data sources from within your application can be accomplished visuallyusing Visual Studio .NET designers, or programmatically by creating data connection objects incode.

    Connecting to an Oracle Database Visually

    Visual Studio supports creating data objects by dragging items from Server Explorer or the Data tabof the Toolbox onto your form or designer.

    To create a connection from Server Explorer

    1. Create a Data Connection in Server Explorer to your Oracle database. For more information,see the above section titled "Connecting to an Oracle database in Server Explorer."

    2. Drag the connect ion onto your form or designer.3. An OracleConnection object appears in the component tray.4. Advance to the sect ion "Next Steps" later in this topic.

    To create a connection from the Data tab of the Toolbox

    1. Drag an OracleConnection onto your form or designer.

    An unconfigured OracleConnection object appears in the component tray.

  • 7/31/2019 Creating Connections to Oracle Databases

    2/3

    5/12 Creating Connections to Oracle Databases

    dn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx

    2. In the Properties window, click the ConnectionString property.3. Select an existing connect ion in the drop-down list, or click New Connection to open the

    Data Link Properties Dialog Box and configure a new c onnection.4. Advance to the sect ion "Next Steps" later in this topic.

    Connecting to an Oracle Database Programmatically

    You can create an OracleConnection object directly in code.

    To programmatically create a connection between your application and an Oracle databaseThe following code creates an OracleConnection object and sets theOracleConnection.ConnectionString property.

    Next Steps

    Now that you have established a connection between your applicat ion and an Oracle database, you

    ' Visual BasicPublic Sub ConnectToOracle()

    Dim conn As New OracleClient.OracleConnection()' TODO: Modify the connection string and include any' additional required properties for your database.conn.ConnectionString = & _"Data Source=;Integrated Security=yes"

    Try conn.Open()' Insert code to process data.

    Catch ex As ExceptionMessageBox.Show("Failed to connect to data source")

    Finallyconn.Close()

    End TryEnd Sub

    // C#public void ConnectToOracle(){

    OracleClient.OracleConnection conn =new OracleClient.OracleConnection ();

    // TODO: Modify the connection string and include any// additional required properties for your database.conn.ConnectionString = "Data Source=" +

    ";Integrated Security=yes";try{

    conn.Open();// Insert code to process data.

    }catch (Exception ex)

    {MessageBox.Show("Failed to connect to data source");

    }finally{

    conn.Close();}

    }

  • 7/31/2019 Creating Connections to Oracle Databases

    3/3

    5/12 Creating Connections to Oracle Databases

    dn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx

    2012 Microsoft. All rights reserved.

    can create object s t o fet ch and update data. The following table provides links to some relevanttopics.

    To See

    Fetch read-only data Retrieving Data Using the DataReader

    Fill a dataset with data ADO.NET Datasets

    Execute SQL statements directly Performing Database Operations Directly

    See Also

    Connecting to Data Sources with ADO.NET | Adding New Data Connections in Server Explorer |Databases in Server Explorer | Oracle Databases | Visual Database Tools | Data Link PropertiesDialog Box

    Did you find this helpful? Yes No