Linq to SQL - Bug?

T

TisMe

Hi All,

I am using Linq to SQL dataclass for my website application.

This was working AOK, but then I deleted and recreated the dataclass
(Seemed the simpliest way of updating the class to reflect DB
structure changes).

Since then, I have to declare the connection differently:

DataClassesContext DB = new DataClassesContect(<4 Overloads, expecting
a connection string or object>);

Before, I did not need to pass a connection string or object, I just
did this:
DataClassesContext DB = new DataClassesContect();

This worked Ok, so I can only assume the connection was defined as
class level within the datacontext.

Question is, why did this change - I added the class the same way I
did originally, dragging tables onto the Linq to SQL surface designer
from an SQL connection in server expolorer.

If I do pass in a connection string I get 'object reference not set to
an instance of an object' when ever a query runs.

Any help/ideas much appreciated!

Thanks,
Simon.
 
M

Michel Walsh

As you said, there are some overload for the context. The one without any
argument uses the default connection (as you can see in the generated code)
which is maintained by the Data Connection you created in your Server
Explorer. You can use the overload specifying a string (connection string)
as argument, so you can easily switch from your testing data context
server/db to your production data context server/db, by changing that string
appropriately.

It may have be that you re-created the data class using another data
connection (even if it is only with some difference in options you used)?


Vanderghast, Access MVP
 
T

TisMe

It may have be that you re-created the data class using another data
connection (even if it is only with some difference in options you used)?

Michael, thanks for your reply - I think you are right here, this is
what caused it. Although I still dont follow why the first time round
resulted in the default connection is used, with no overloads on the
context, yes the 2nd time round resulted in the overloaded method.
i.e. What specifically, within the server mananger connection object,
causes this behavour to differ?
 
M

Michel Walsh

I am not sure, I don't know the mechanic involved behind that scene.

Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top