tags:

views:

22

answers:

2

hi! Started working after some days off, and generated a new dbml file through vs 2008. then it sent an error:

Object reference not set to an instance of an object. MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("C__USERS_JIMMY_DOCUMENTS_VISUAL_STUDIO_2008_WEBSITES_LUNCHGUIDEN_APP_DATA_LUNCHGU"& _ row 88:"IDEN_MDFConnectionString").ConnectionString, mappingSource)

its like the dbml generates an own connection string, but i have done this alot of times before without it happening?

the problems is when i put it up on a sharp server.. it obviously cant find the connectionstring. what to do so the connectionstring doesnt get generated wrong?

A: 

Use the datacontext constructor with the connectionstring in parameter so it will not look after the default one

Ex:

using(MyDbContext context = new MyDbContext(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString))
{
    ...
}
Gregoire
MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("LunchguidenConnectionString").ConnectionString, mappingSource) OnCreated() Public Sub New() MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("LunchguidenConnectionString").ConnectionString, mappingSource) OnCreated() End Sub End Sub
Jimmy
A: 

Could it be that while you added a new entity to the model that the appSettings have been generated? It seems that linq to sql is always storing the connectionstring of the entity that was previously added to the model.

Yves M.