Вы находитесь на странице: 1из 3

5/5/12

Creating Connections to Oracle Databases

Creating Connections to Oracle Databases


Visual Studio .NET 2003 8 out of 20 rated this helpful - Rate this topic 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. Using Windows 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 Explorer


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

Connecting to an Oracle Database from within your application


Creating connections to data sources from within your application can be accomplished visually using Visual Studio .NET designers, or programmatically by creating data connection objects in code.

Connecting to an Oracle Database Visually


Visual Studio supports creating data objects by dragging items from Server Explorer or the Data tab of 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 connection onto your form or designer. 3. An OracleConnection object appears in the component tray. 4. Advance to the section "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.
msdn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx 1/3

5/5/12

Creating Connections to Oracle Databases

2. In the Properties window, click the ConnectionString property. 3. Select an existing connection in the drop-down list, or click New Connection to open the Data Link Properties Dialog Box and configure a new connection. 4. Advance to the section "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 database The following code creates an OracleConnection object and sets the OracleConnection.ConnectionString property. 'Vsa Bsc iul ai Pbi SbCnetorce) ulc u oncTOal( Dmcn A NwOalCin.rceoncin) i on s e rceletOalCneto( 'TD:Mdf tecneto srn adicueay OO oiy h oncin tig n nld n 'adtoa rqie poete fryu dtbs. diinl eurd rpris o or aaae cn.oncintig=&_ onCnetoSrn "aaSuc=oal dt suc nm>Itgae Scrt=e" Dt ore<rce aa ore ae;nertd euiyys Ty r cn.pn) onOe( 'Isr cd t poesdt. net oe o rcs aa Cthe A Ecpin ac x s xeto Msaeo.hw"aldt cnett dt suc" esgBxSo(Fie o onc o aa ore) Fnly ial cn.ls( onCoe) EdTy n r EdSb n u / C / # pbi vi Cnetorce) ulc od oncTOal( { OalCin.rceoncincn = rceletOalCneto on nwOalCin.rceoncin(; e rceletOalCneto ) / TD:Mdf tecneto srn adicueay / OO oiy h oncin tig n nld n / adtoa rqie poete fryu dtbs. / diinl eurd rpris o or aaae cn.oncintig="aaSuc= + onCnetoSrn Dt ore" "oal dt suc nm>Itgae Scrt=e" <rce aa ore ae;nertd euiyys; ty r { cn.pn) onOe(; / Isr cd t poesdt. / net oe o rcs aa } cth(xeto e) ac Ecpin x { Msaeo.hw"aldt cnett dt suc"; esgBxSo(Fie o onc o aa ore) } fnly ial { cn.ls(; onCoe) } }

Next Steps
Now that you have established a connection between your application and an Oracle database, you
msdn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx 2/3

5/5/12

Creating Connections to Oracle Databases

can create objects to fetch and update data. The following table provides links to some relevant topics.

To
Fetch read-only data Fill a dataset with data Execute SQL statements directly See Also

See
Retrieving Data Using the DataReader ADO.NET Datasets Performing Database Operations Directly

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 Properties Dialog Box

Did you find this helpful?

Yes

No

2012 Microsoft. All rights reserved.

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

3/3

Вам также может понравиться