472,958 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Linq to SQL - Bug?

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.
Jul 3 '08 #1
3 1746
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
"TisMe" <si**********@googlemail.comwrote in message
news:26**********************************@k13g2000 hse.googlegroups.com...
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.
Jul 3 '08 #2
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?
Jul 7 '08 #3
I am not sure, I don't know the mechanic involved behind that scene.

Vanderghast, Access MVP

"TisMe" <si**********@googlemail.comwrote in message
news:69**********************************@k30g2000 hse.googlegroups.com...
>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?

Jul 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.