Connecting to Northwind via path

  • Thread starter Thread starter CES
  • Start date Start date
C

CES

All,
I've been able to get my Entity Data Model to work but I'm having problems
with a normal ADO Connection. I'm really new to all of this and I can't seem
to find a way to connect to Nortwind via a direct path ie:
C:\Temp\NORTHWND.MDF within a console app.

The MSDN Article http://msdn.microsoft.com/en-us/library/dw70f090.aspx shows
everything except using a direct path. If anyone knows of A SIMPLE example
of a complete database call (in C#) I would be grateful.
 
The code in your quoted link is based on the fact that there is a local
default SQL Server instance, which has a database called "Nothwind", hence
the code like this:

Dim connectionString As String = _
"Data Source=(local);Initial Catalog=Northwind;" _
& "Integrated Security=true"

It looks like you need to know a bit more on SQL Server (most .NET code
samples assume the developer know the very basic SQL Server thing when the
samples deal with data from SQL Server). You do not directly connect/access
to *.mdf file. This file is exclusively used by SQL Server. The only time
you need to deal it directly is when you need to attach the *.mdf file to
SQL Server so that a database based on this *.mdf file is created with the
SQL Server. Then you connect to this database to access data. Once the *.mdf
file is attached to SQL Server, nothing can access it except for SQL Server.

If you find some sample code that has "AttachDBFile=... " and "USER
INSTANCE=true", try to avoid it until you really know what "USER INSTANCE"
means (study on SQL Server BOL).
 
Back
Top