.NET Framework - Northwind DB compile error

Asked By Space Cowboy on 29-Mar-11 02:34 PM
I cant get accessdb.cs to compile.  I show my
directory,program,compile.  The directory came from a book zip.  I
created the Northwind.dll from Northwind.cs which contains the
namespace nwind.  The crux of the problem is Northwind.cs which I
assume was created from SQLMETAL which is a mapping of Northwind.mdf.
It shows Northwind takes 2 parameters.  Every Internet example shows
just the connect string.

I know Im probably barking up the wrong tree.  When I get past the
compile error then I assume I need to have
some SQL service running.  Im hoping LINQ didnt need a SQL service
with Data Source(local).

Ill settle for a clean compile and then worry about the runtime.

Thanks,
Jim

03/29/2011  10:42 AM    <DIR>          .
03/29/2011  10:43 AM               230 accessdb.cs
03/29/2011  04:55 AM           143,697 Northwind.cs
03/29/2011  04:55 AM            39,935 Northwind.dbml
03/29/2011  05:37 AM            86,016 Northwind.dll
03/29/2011  04:55 AM         4,194,304 Northwind.mdf
03/29/2011  04:55 AM            41,416 Northwindmap.xml
03/29/2011  04:55 AM         1,048,576 Northwind_log.LDF

findstr /i Northwind Northwind.cs

public Northwind(string connection,
System.Data.Linq.Mapping.MappingSource mappingSource) :
public Northwind(System.Data.IDbConnection connection,
System.Data.Linq.Mapping.MappingSource mappingSource) :

type accessdb.cs

using System;
using System.Data.Linq.Mapping;
namespace nwind
{
class database
{
static void Main()
{
nwind.Northwind db = new nwind.Northwind(@"Data
Source=(local);Initial Catalog=Northwind");
}
}
}

csc /r:Northwind.dll accessdb.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
accessdb.cs(9,28): error CS1729: 'nwind.Northwind' does not contain a
constructor that takes '1' arguments
Northwind.dll: (Location of symbol related to previous error)




Big Steel replied to Space Cowboy on 29-Mar-11 07:56 PM
That I know of it is suppose to be like this.

nwind.Northwind db = new nwind.Northwind();

The compile error is telling you that the object you are trying to
create new does not take a parameter.

I do not know where you came up with that code, but obviously it is not right.
Space Cowboy replied to Space Cowboy on 30-Mar-11 09:37 AM
You talking to me.  One foot forward.  The following compiles with
warnings and executes with a runtime error it couldnt find a SQL
server.  The Table entry I picked up from MSDN and generates conflict
warnings with the Table Customer in nwind otherwise it wouldnt compile
GetTable<Customer>.  The mappingsource I picked up from SQL website.
I get exactly the same runtime error if I use the ADO DataContext.

Its too bad all the Northwind DB LINQ examples assume alot of other
stuff that doesnt get mentioned.

using System;
using System.Linq;
using System.Data.Linq.Mapping;
using System.Data.Linq;
namespace nwind
{

[Table(Name =3D "Customer")]
public class Customer
{
[Column(IsPrimaryKey =3D true)]
public string CustomerID;
[Column]
public string City;
}

class database
{
public static System.Data.Linq.Mapping.MappingSource mappingSource
=3D new AttributeMappingSource();
static void Main()
{
nwind.Northwind   db =3D new nwind.Northwind(@"Data
Source=3D(local);Initial Catalog=3DNorthwind",mappingSource);
// DataContext db =3D new DataContext("Northwind.mdf");
Table<nwind.Customer> Customers =3D
db.GetTable<nwind.Customer>();
var q =3D from c in Customers where c.City =3D=3D "London" select c;
foreach (var cust in q)
{
Console.WriteLine("id =3D {0}, City =3D {1}", cust.CustomerID,
cust.City);
}
}
}
}
Big Steel replied to Space Cowboy on 30-Mar-11 09:50 AM
Not to be smart here, but you seem to be talking to yourself.

Anyway, why do not you just keep it simple for now, before you try to do
more complicated things?
Space Cowboy replied to Big Steel on 30-Mar-11 11:54 AM
I was referring to replying to my own post.  Your link is just another
example of some magic behind the scene that the Visual Studio takes
care of for you.  Who knows maybe it is making Registry entries for
the DB.  At the minimum I would expect to see a connection string.  My
LINQ example couldnt get more trivial, retrieving records from a DB.
When I resolve the connection problem Ill post back.  The Table class
is an example ORM table entity mentioned in MSDN describing
NorthWind.  It clashes with what is apparently generated by SQLMETAL
in the Northwind.cs DB mapping.
Big Steel replied to Space Cowboy on 30-Mar-11 12:33 PM
No, it made a connection string that is kept in the app.config file that
the project is using that winds up in the ProgramName.exe.Config file
when you build the solution, which is specific to what Link-2-SQL is
doing and where it expects to find the connection string.


Maybe you are not looking in the right place. Maybe you are not doing
the correct things, which may be your case.

Retrieving data and getting a connection to retrieve the data are two
different things.


I do not think you should be messing around with generated code, if
that is what you are doing. That compile error message you got is
explicitly telling you that the obj = new obj() cannot take a parameter
because there is no constructor with the signature in the class that is
going to take a pram.

error CS1729: 'nwind.Northwind' does not contain a
constructor that takes '1' arguments

You must be misinterpreting the information. Maybe you need to take
another path.

If you want to do things yourself explicitly, then switch to ADO.NET
Entity Framework and CTP5.