Database Reference
In-Depth Information
Figure 12-4. Displaying OLE DB connection information
How It Works
We'll discuss only the differences between this example and the previous one. The first step is to
reference the OLE DB data provider namespace.
System.Data.OleDb.
using System.Data.OleDb;
Next, you create an OleDbConnection object instead of a SqlConnection object. Note the changes to
the connection string. Instead of the server parameter, you use Provider and Data Source . Notice the
value of the Integrated Security parameter must be sspi , not true .
// create connection
OleDbConnection conn = new 01eDbConnection(@"provider = sqloledb;data source = .\sql2012;
integrated security = sspi;" );
Finally, note that you omit the Workstationld property in your display. The OLE DB data provider
doesn't support it.
This is the pattern for accessing any data source with any .NET data provider. Specify the
connection string with parameters specific to the data provider. Use the appropriate objects from the
data provider namespace. Use only the properties and methods provided by that data provider.
Summary
In this chapter, you created, opened, and closed connections using two data providers and their
appropriate connection strings, parameters, and values. You displayed information about connections
after creating them using connection properties. You also saw how to handle various exceptions
associated with connections.
In the next chapter, you'll look at ADO.NET commands and see how to use them to access data.
 
Search WWH ::




Custom Search