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
Register | FAQ | Members List | Calendar | 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 July 17th, 2012, 02:09 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default connectionString using EF

Hi,

I am stuck. I have spent nearly a day to solve but to no avail.

PROBLEM: Connecting to production database using entity framework.

I connect fine on development.

<add name="DefaultConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MONDO;Integrated Security=True" providerName="System.Data.SqlClient" />

<add name="MONDOEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=MONDO;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

Moving to production, I used (from the production web.config file) the existing "DefaultConnectionString" parameters (ID and Password) to edit the MONDOEntities connectionString. (can I do this?) Also, I expanded the metadata in MONDOEntities to include .csdl, .ssdl, .msl and I prefixed it with (guessing, again, can I do this?) MONDO. Bold parts are changes from dev web.config to production web.config. *Note, the connectionStrings below were not created by Visual Studio, I just changed the bolded info myself to try and make it work on the production side.

<add connectionString="Data Source=MPOC\SQLEXPRESS;Database=Mondo;User ID=xxx;Password=xxxxx;" name="DefaultConnectionString" />

<add name="MONDOEntities" connectionString="metadata=res://*/MONDO.csdl|res://*/MONDO.ssdl|res://*/MONDO.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MPOC\SQLEXPRESS;persist security info=True;Database=Mondo;User ID=xxx;Password=xxxxx;MultipleActiveResultSets=Tru e;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

The error message I get is:
Unable to load the specified metadata resource.

Line 62: /// Initializes a new MONDOEntities object using the connection string found in the 'MONDOEntities' section of the application configuration file.
Line 63: /// </summary>
Line 64: public MONDOEntities() :


QUESTION: Can I simply modify the connectionStrings manually or does it need to run through a compilation process? It is a website project so it compiles, on the fly, the first time after I upload to production. It does not get precompiled on my local dev computer. I guess, bottom line, how do I set up a proper connectionString for an entity connection for a database in production?
Reply With Quote
  #2 (permalink)  
Old July 17th, 2012, 02:19 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You should normally be able to just take the entire connection string and just change the parts in the provider connection string. There's no need to change the other parts.

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 July 17th, 2012, 07:01 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default

Hi Imar,

I'm on a project where I need to learn an existing website. I'm making my first bug fix and having learned ado.net (from your book), I created an entity data model and made some code changes. Everything works smooth in development.

I move the files to production and then I get this error:

Code:
"The specified default EntityContainer name 'MONDOEntities' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName"
I googled this error message and based on some findings, I expanded my "metadata" shown below. This was more of a shot in dark for me:

ORIGINAL (auto generated in web.config when I created the entity data model):
Code:
connectionString="metadata=res://*
NEW (I edited/added this):
Code:
connectionString="metadata=res://*/MONDO.csdl|res://*/MONDO.ssdl|res://*/MONDO.msl;
This seemed to get past the first error and I get to a new error message (as posted in OP):

Code:
Unable to load the specified metadata resource.

Line 62: /// Initializes a new MONDOEntities object using the connection string found in the 'MONDOEntities' section of the application configuration file.
Line 63: /// </summary>
Line 64: public MONDOEntities() :
I think that there is a problem with my metadata information. However, given that the original, auto generated connectString only contains "metadata=res://*", I really don't know how to go about correcting this. Actually, I'm not even super sure that this is the root of the problem.

Bottom line, my entity model works smooth in dev but isn't connecting in production. Any thoughts are appreciated ... thanks.

Last edited by nanonerd; July 17th, 2012 at 07:04 PM..
Reply With Quote
  #4 (permalink)  
Old July 18th, 2012, 04:24 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Is this a web site projector a web application project? And how did you deploy the updated EF model to the server?

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 July 18th, 2012, 12:56 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Accidently did a precompile

Imar,

Based on seeing an App_Code directory, it is a website project (right?).

On my dev computer using VS 2012 (commercial, not express), I created a new entity data model (mondo.edmx) based on the existing database. On the dev side, everything works as it should.

I believe now, upon more reflection this morning, that I might have err'ed in deploying.

1) After creating the EDM, I made a code fix and since it's a website project, I tried to copy just three files (cust.aspx, cust.aspx.cs, web.config (connectString modified to point to prod database)) using the Copy Website (via FTP).

2) But being a dumb dumb, I forgot to copy the new mondo.edmx file as well. When I was getting errors on the production side, in a fit of confusion, I did a pre-compile on my dev computer. When I looked at the pre-compiled files, it didn't look like the stuff on production so I didn't copy the pre-compiled files over.

3) Then, even though I thought this was overkill, I decided to copy the entire site over (not the precompiled version, rather the source files) ... at some point, I realized that I'd forgetten the mondo.edmx file in step 1 above. But too late, everything was copied over.

QUESTIONS:

- in step 1, would it have been correct to copy just 4 files (cust.aspx (changes made), cust.aspx.cs (changes made), web.config (changes made), and mondo.edmx (new file) ...
- given that I did a pre-compile on my dev machine in step 2, and then instead of copying over the pre-compiled files, I copied all the original source code instead, could this be causing confusion on the production machine in finding the mondo.edmx file, etc.?

I'm not exactly sure on the gritty technical details of a compile. But I'm guessing that the metadata that the web.config is looking for is in the app_code.dll in the precompile on my dev machine. If I had done things correctly by just deploying the 4 files described above, perhaps the website would have compiled in production properly and the metadata would have been properly located in the compiled assembly in production. <<< This paragraph is guesswork on my part.

Well, I guess that's my theory at this point, although I could be totally off base. Thoughts please?
Reply With Quote
  #6 (permalink)  
Old July 19th, 2012, 03:16 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
Based on seeing an App_Code directory, it is a website project (right?).
Most likely. Another way is to check code behind files. Web Forms in WSPs have 1, and in WAPs they have 2.

Quote:
- in step 1, would it have been correct to copy just 4 files (cust.aspx (changes made), cust.aspx.cs (changes made), web.config (changes made), and mondo.edmx (new file)
It depends. If your deployed site is not precompiled this works for the most part. However, you also need to copy the code behind file for the edmx (e.g. mondo.Designer.cs).

Quote:
- given that I did a pre-compile on my dev machine in step 2, and then instead of copying over the pre-compiled files, I copied all the original source code instead, could this be causing confusion on the production machine in finding the mondo.edmx file, etc.?
It depends. You could mix and match compiled and non-compiled files but I wouldn't recommend it. Either compile the entire app, or compile no files at all.

Quote:
I'm not exactly sure on the gritty technical details of a compile. But I'm guessing that the metadata that the web.config is looking for is in the app_code.dll in the precompile on my dev machine.
Correct. Your model should be compiled into the app_code.dll. Using a tool such as Red Gate's Reflector you can look into that DLL and you'll see your entity types.

Quote:
If I had done things correctly by just deploying the 4 files described above, perhaps the website would have compiled in production properly and the metadata would have been properly located in the compiled assembly in production. <<< This paragraph is guesswork on my part.
Perhaps ;-) I am bit lost on what you did and what did and what didn't work so I can't tell for sure.

With regards to your connection string, I am bit surprised about the metadata. This is what I get when I generate a new model:

Code:
metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;
This works for me with the model in App_Code as well as in a precompiled site.

Hope this helps,

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 July 19th, 2012, 01:28 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Convert older websites to 4.0

I think I know what the problem is.

The website was originally built in asp.net 3.5. Somehow, when I loaded it, I didn't convert it to 4.0. Working with the 3.5 framework, this seems to have caused a few issues:

1) when creating the mondo.edmx, it's doesn't all the inclusion of foreign keys (option is unchecked and grayed out); this caused me a lot of angst when trying to write queries and the foreign key wasn't showing up in the entity property list - I finally found a way to code around this but it is more convoluted and def not fun ... this isn't directly related to my issue in OP but the solution to my OP appears to correct this problem as well ...

2) 3.5 doesn't create a proper connection string w/ respect to the metadata


I made another website copy and upon opening VS, chose to convert to 4.0 (prompt comes up asking). This resolved both issues above. When creating the entity data model, the foreign key inclusion option is checked and not grayed out. Plus, the connection string looks proper as shown below:

Code:
connectionString="metadata=res://*/App_Code.mondo.csdl|res://*/App_Code.mondo.ssdl|res://*/App_Code.mondo.msl;
So far, this is looking good on the dev side ... but I can't confirm the production side until early next week (long story) 'cause I probably can't move things to production till then ... will post follow up next week ...

Thanks Imar for all the insights !
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
DataContext Lifetime : Structure Map + EF fillie76 BOOK: Professional ASP.NET Design Patterns 0 January 6th, 2012 02:20 PM
LINQ to EF eqiuvalent for SQL LIKE malie22001 BOOK: Beginning ASP.NET 4 : in C# and VB 2 December 13th, 2011 05:42 AM
Generic Question and EF vbboyd BOOK: Beginning ASP.NET 4 : in C# and VB 4 May 19th, 2011 04:14 PM
Questions related to ADO.NET EF and one unrelated Rushino ASP.NET 4 General Discussion 6 July 29th, 2010 08:41 AM
Tracing connectionstring miguel.ossa ASP.NET 2.0 Basics 4 January 8th, 2008 04:24 PM



All times are GMT -4. The time now is 02:16 AM.


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