Connecting to a Data Store

In the following sections, we’ll use the Northwind database that ships with the .NET Framework SDK. To access this data source, we’ll use the classes from the SqlClient namespace. We’ll highlight any differences between the use of the classes in the SQL and OLE DB libraries where they are relevant.

Connecting to a Data Source (OLE DB and SQL)

To connect to a database, you must create a SqlConnection object. The simplest way to do this is to pass a connection string as a parameter to the SqlConnection constructor, as shown here:

String conString = "data source=(LOCAL);    initial catalog=Northwind;    integrated security=SSPI;    persist security info=False;    workstation id=(LOCAL);packet size=4096"; SqlConnection con = new SqlConnection(conString); ...

Get Microsoft® Visual J#™ .NET (Core Reference) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.