Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 13th, 2013, 02:18 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old May 13th, 2013, 02:59 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old May 14th, 2013, 01:44 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

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
Reply With Quote
  #4 (permalink)  
Old May 14th, 2013, 02:12 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old May 14th, 2013, 02:34 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old May 14th, 2013, 02:38 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old May 24th, 2013, 11:35 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old May 25th, 2013, 01:09 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Default

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.
Reply With Quote
  #9 (permalink)  
Old May 25th, 2013, 07:32 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #10 (permalink)  
Old May 25th, 2013, 01:50 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using entity framework 5 misuk11 BOOK: Professional ASP.NET Design Patterns 1 February 25th, 2014 05:23 PM
Entity Framework vbboyd BOOK: Beginning ASP.NET 4.5 : in C# and VB 5 January 18th, 2013 11:48 AM
Hosting and the web.config file, connection string for Entity jdlferreira BOOK: Beginning ASP.NET 4 : in C# and VB 56 November 10th, 2012 01:19 AM
The BeerHouse and Entity Framework docluv BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 3rd, 2008 01:32 PM



All times are GMT -4. The time now is 02:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.