 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 13th, 2013, 02:18 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Connection string with Entity Framework
Hello all,
I want to design a 3 layer architecture based project. For Data handling I am using Entity Framework file in DAL project.
The main problem is the connection string. I have connection string in app.config file in DAL, but when I run the project I get the error
Quote:
|
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
|
To get rid of this error I pasted the same connection string from app.config to web.config file of the web project. and it then works. But I do not want to include any DB information in web.config file because the web project is public, and using same DAL, BAL I want to create more web based projects.
Is there any way so that we can run project successfully even not giving DB connection details in web.config file.
Please help me in this.
Thanks
|
|

May 13th, 2013, 02:59 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
This is by design. The assemblies from your separate projects are copied into the web application's Bin folder; they are not run from their original location where their app.config lives and as such that file is never used. This means that the web application's root folder is the configuration root for the site and the assemblies it uses, and as such is the perfect place for your connection strings.
Why don't you want to store them there?
Imar
|
|

May 14th, 2013, 01:44 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Hi Imar,
Quote:
|
Why don't you want to store them there?
|
Well there is no any concrete reason for this but still few exist.
1. There will be a lot of web projects based on this DAL, BAL. So that every time we switch the connection string in DAL, we have to manually line up the correct connection string in web projects.
2. Although web.config is not accessible online but it can be viewed if someone knows FTP. Though the person is not too technical who has access to the FTP but still want to keep away any DB information.
3. It works in case of DBML files but problem with EDMX files.
So I am not able to figure out the more appropriate reason but I know it was possible in DBML files then how it can be done in EDMX.
Thanks
|
|

May 14th, 2013, 02:12 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Well. you have to store the connection strings somewhere. I see a few options:
1. Store them in web.config. Preferred, IMO. You can encrypt connection strings to keep them from being read by people with FTP access.
2. Configure them in code. However, that's worse as it means you need to redeploy your assemblies every time the connection string changes.
3. You could store them in Machine.config so they apply to all sites using it.
Google knows more about each of these solutions.
Quote:
|
Although web.config is not accessible online but it can be viewed if someone knows FTP.
|
Well, that would be true regardless where you store them, even if you add them to code if you don't take protective measures. And if someone has unauthorized access to FTP you have other problems to worry about.
Quote:
|
It works in case of DBML files but problem with EDMX files.
|
It works for me. What problems are you having?
Imar
|
|

May 14th, 2013, 02:34 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Quote:
|
It works for me. What problems are you having?
|
In DBML we set connection string in app.config in DAL project and then build it, no need to paste the same connection string in web.config and it works.
But for EDMX we have to copy the same connection string in web.config, which I don't like to do.
What actually you do so that it works for you? Do you also paste same connection string in web.config? if this is not so then how you do it?
Thanks
|
|

May 14th, 2013, 02:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
In DBML we set connection string in app.config in DAL project and then build it, no need to paste the same connection string in web.config and it works.
|
I find that hard to believe. The app.config is never copied into the web site's root or other folder. Can you describe how you do it?
Quote:
|
Do you also paste same connection string in web.config?
|
Yes, I use web.config Transformations to create various versions for development, test, production etc. and then deploy.
Cheers,
Imar
|
|

May 24th, 2013, 11:35 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Hi Imar,
I have sent you zip file on you email ID which contains readme.txt file and project.
I have tried to mention everything in the readme file.
Please have a look on that.
Thanks
|
|

May 25th, 2013, 01:09 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
I just checked that mail failed, after that I tried 3 more times but mail did not get sent to you.
Please tell me how I can send you attachment.
|
|

May 25th, 2013, 07:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
And why would you be sending me e-mails with attachments? IMO, it's against netiquette to send forum members messages like that, especially if they are large (that's probably also why the mail was rejected).
Why not post the relevant code here or make it online somewhere (drop box, Google docs, whatever).
Imar
|
|

May 25th, 2013, 01:50 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Quote:
|
I find that hard to believe. The app.config is never copied into the web site's root or other folder. Can you describe how you do it?
|
I wanted to show that the DBML project does not require connection string to be in web.config of Web.
Quote:
especially if they are large (that's probably also why the mail was
rejected).
|
It was just 511 KB.
Quote:
|
make it online somewhere (drop box, Google docs, whatever).
|
Nice Idea, I'll upload there sooner
|
|
 |