开发者

linq to sql generates an faulting connectionstring

Started working after some days off, and g开发者_开发百科enerated 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?


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))
{
    ...
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜