O'Reilly logo

Microsoft® Visual J#™ .NET (Core Reference) by John/Longshaw, Andy Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required