ODBC (Open Database Connectivity)

for RuBoard

Though there is no ODBC .NET provider included with the Microsoft .NET Framework SDK, you can download one for free at http://www.microsoft.com/data. You can use this provider to connect to any valid ODBC source. Though ODBC is usually not an optimal choice, if you are unable to find a managed or OLE DB provider for your data source, you most likely will be able to find an ODBC driver.

You can use the following code to create a new instance of the ODBC Connection object:

 Dim conn as OdbcConnection = New OdbcConnection("dsn=myDSN;UID=myUid;PWD=;") 

The preceding OdbcConnection object is using a DSN (Data Source Name) to connect to the data source. A DSN provides a layer of abstraction in connecting to your ODBC data source. By creating a DSN, you specify the details of the connection in one location. This enables you to just enter the name of the DSN and any user authentication information in your connection string. To create a DSN for your ODBC data source, follow these steps:

  1. In your computer's Control Panel, locate the ODBC Data Source Administrator. The name of the Control Panel applet differs between operating systems, but in all cases the name contains "ODBC." In Windows 2000, it's the Data Sources (ODBC) icon in the Administrative Tools folder. When the ODBC Data Source Administrator is running, click on the System DSN tab. Your screen will look like the one in Figure 5.1.

    Figure 5.1. The ODBC Data Source Administrator.


  2. Click the Add button to add a new System DSN. On the next screen, you're prompted to choose the ODBC driver that the DSN will use to connect to your data source. Choose the appropriate ODBC driver.

  3. The next screen is specific to the ODBC driver chosen . If you chose the Microsoft Access driver in step 2, you're presented with the screen in Figure 5.2. After filling out all required fields for your data source, a new DSN is added to your system, which you can then reference from your application. Keep in mind that if you deploy your application to another machine, you will need to re-create the DSN on that machine in order for your code to work.

    Figure 5.2. Adding an ODBC connection to a Microsoft Access database.



Do not use an ODBC DSN to connect to your data source if a managed provider or OLE DB provider is available. The latter two options will give you the best performance.

for RuBoard

Sams Teach Yourself ADO. NET in 24 Hours
Sams Teach Yourself ADO.NET in 24 Hours
ISBN: 0672323834
EAN: 2147483647
Year: 2002
Pages: 237

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net