Get the connection string for Entity Framework using the POCO template?

I get the DB connection like this var connection = (SqlConnection)_context.Database. Connection Then from connection you get the ConnectionString and other info you need.

I get the DB connection like this var connection = (SqlConnection)_context.Database. Connection; Then from connection you get the ConnectionString and other info you need.

There must be a connectionString-element present in the web. Config that the specified name used on the context.

I am using a entity framework on a class library project. I don't have a web.config. All the connection string stuff is in App.

Confg and looks more like this: connectionString="metadata=res://*/MyDataModel. Csdl|.... The provider name is providerName="System.Data. EntityClient" – Vaccano Jul 5 at 18:34 Does this connectionString has a name-attribute?

It should match the actual connection-string passed to the context, you've mentioned. – J. Tihon Jul 5 at 18:42 Yes there is a name property.It is the same as the part after name= in the code for the property for the connection string.

I just don't know how to use that to load the actual connection string from App. Config and use it in the code. I tried ConfigurationManager.

ConnectionStrings"MyAppConfigConnectionStringPropertyHere"?. ConnectionString and it fails. When I dig into the connection strings list (using the debugger) my connection string is not in there.

(it only has a connection to my localhost sql server). – Vaccano Jul 5 at 18:58 Turns out that I had the data in the wrong app.config.My class library that held my entities was being run by a different project that was a WCF Service Library. Once I moved the connection string to that app.

Config it all worked great. – Vaccano Jul 5 at 19:10.

I use Entity Framework and I need to get my connection string so I can construct a context. I am using the POCO template. I saw in this answer that indicated that there is a GetConnectionString() method.

But googling has not lead me to the reference I need to add to get that method (it is not in my project by default). So, I can't think that I am the first one who wants to get a connection string for entity framework using the POCO templates. How have others done this?

I guess I can just read in the whole app.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions