Page 1 of 1
Connection String without web.config?
Posted: Wed 09 Feb 2011 21:33
by ColorsFade
I could not find this in the documentation, but I am wondering how I can setup the ObjectContext without using the web.config to store the connection string.
I noticed while looking at the generated code for the base ObjectContext that there are three constructors. One takes a EntityConnection as a parameter and another version takes a connection string.
Is there a way to do this?
Thanks.
Posted: Thu 10 Feb 2011 13:57
by AndreyR
You can use the ObjectContext constructor that takes a connection string, like in the following example:
Code: Select all
Entities1 db = new Entities1("metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=Devart.Data.Oracle;provider connection string=\"User Id=andreyr;Password=*;Server=*;Persist Security Info=True\"")
As an alternative, you can use the constructor that takes an EntityConnection parameter, initializing the EntityConnection using the
EntityConnectionStringBuilder class.
Posted: Thu 10 Feb 2011 14:25
by ColorsFade
Thanks Andrey, but that doesn't help much. See, I'm using a DomainContext and not newing up the entities like you are.
Code: Select all
[EnableClientAccess()]
public class ProjectStaffingService : LinqToEntitiesDomainService
I have no idea how to handle this and we cannot allow the connection string to be in the app.config.
Posted: Thu 10 Feb 2011 15:08
by ColorsFade
I figured it out. You have to overwrite the CreateObjectContext() method in the service.
Posted: Thu 10 Feb 2011 16:19
by AndreyR
You are correct. Thank you for sharing the solution.