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 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 22nd, 2012, 07:33 PM
Authorized User
Points: 113, Level: 2
Points: 113, Level: 2 Points: 113, Level: 2 Points: 113, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default Hosting and the web.config file, connection string for Entity

So I've been playing around with Chapter 14, ADO.net and Linq, I created my Entities by making the following:
Code:
using (orangefreshEntities myEntities = new orangefreshEntities())
        {
            var allPosts = (from post in myEntities.Posts
                           orderby post.Id descending
                           select new { post.Title, post.Body, post.Summary, post.CreateDateTime }).Take(3);
            Repeater1.DataSource = allPosts;
            Repeater1.DataBind();
        }
So I proceed to host my project, make my changes in web.config, change the connection string for my database with the string provided by my host, but now I need to change the connection string for the Entities, which I'm not too sure what to do here, I'm getting the following error:
Quote:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Which I'm guessing comes from not changing the connection string for the Entities, any idea what to do in my web.config file?
Reply With Quote
  #2 (permalink)  
Old July 23rd, 2012, 03:44 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

The Entitites connection string has an embedded provider connection string that you must update with your host's details, just like you updated the other connection string.

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
  #3 (permalink)  
Old July 23rd, 2012, 12:03 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

Quote:
The Entitites connection string has an embedded provider connection string that you must update with your host's details, just like you updated the other connection string.
Yes that's true, but as data source information is repeated in entity connection string. so isn't there a way to address data source property of entity connection string with the connection string of database?

something like:

Quote:
<add name="PlanetWroxConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\PlanetWrox.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />

<add name="PlanetWroxEntities" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlCl ient;provider connection string=&quot;PlanetWroxConnectionString1;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
Many thanks
Reply With Quote
  #4 (permalink)  
Old July 23rd, 2012, 01:01 PM
Authorized User
Points: 113, Level: 2
Points: 113, Level: 2 Points: 113, Level: 2 Points: 113, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

The host I'm using is a free host at somee.com, the only connection string I'm given is:

Code:
workstation id=orangefresh.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxx;data source=orangefresh.mssql.somee.com;persist security info=False;initial catalog=orangefresh
I've been trying to twist this around to fit in the Entity framework connection string, but no luck so far.

Would this be a completely different string from that?
Reply With Quote
  #5 (permalink)  
Old July 23rd, 2012, 01:23 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
so isn't there a way to address data source property of entity connection string with the connection string of database?
As far as I know: no, you can't. You may be able to change the code in the designer file to support this but that would get overwritten each time you regenerate the model. You could work around that by writing your own T4 temlates, but that could be pretty messy.
I would just manually specify the concetion string twice in Web.config and be done with it.

Quote:
Would this be a completely different string from that?
No, what you posted looks like a normal connection string (with a few additional attributes) using SQL Authentication to me. Look at appendix B for more examples and an explanation. Your connection string would go between the "quotes" of the provider connection string.

Can't recommend anything else as this:
Quote:
I've been trying to twist this around to fit in the Entity framework connection string, but no luck so far.
doesn't really explain what the problem is.

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!

Last edited by Imar; July 23rd, 2012 at 01:26 PM..
Reply With Quote
  #6 (permalink)  
Old July 23rd, 2012, 01:49 PM
Authorized User
Points: 113, Level: 2
Points: 113, Level: 2 Points: 113, Level: 2 Points: 113, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

The connection string I posted is the only string my host provides.

I replaced the default string in my web.config file with it, in "orangefreshConnectionString1" (PlanetWroxConnectionString1 in the book)

Now I'm left with the Entity connection string, I don't know what to replace the default string with.

What I was wondering was, is this string (the one posted) supposed to function as well in my Entity connection string? Because I tried using the string on both the connection strings and I still get an error.
Reply With Quote
  #7 (permalink)  
Old July 23rd, 2012, 02:30 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I am not sure I understand all this. Part of that is caused by the fact you're not posting a lot of relevant information. Based on "I still get an error" it's very hard to suggest how to fix it.

Also, posting your current code would help. In summary: you need both connection stirngs as they were used in the demo site. For the standard connection string, replace everything with what your provider gave you. For the EF connection string, just replace the part between &quot;'s (e.g. the provider connection stirng) and leave everything else in these.

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
The Following User Says Thank You to Imar For This Useful Post:
jdlferreira (July 23rd, 2012)
  #8 (permalink)  
Old July 23rd, 2012, 02:49 PM
Authorized User
Points: 113, Level: 2
Points: 113, Level: 2 Points: 113, Level: 2 Points: 113, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Yep! I think I got to the answer the same time you posted it...

The trick was putting the connection string in between the $quot 'marks'. Sorry for not being totally clear, connection strings are still a dodgy field for me...
Reply With Quote
  #9 (permalink)  
Old July 23rd, 2012, 03:28 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

OK, so does it work now?

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 July 23rd, 2012, 04:02 PM
Authorized User
Points: 113, Level: 2
Points: 113, Level: 2 Points: 113, Level: 2 Points: 113, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Fully working now!

http://www.jdlferreira.somee.com/index.aspx

The boxes at the bottom of the page make use of LINQ. Before fixing up the web.config file I obviously could not navigate to this page.
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
Storing Connection String in web.config TeaDrinkingGeek BOOK: Beginning ASP.NET 4 : in C# and VB 1 March 14th, 2011 10:42 AM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
setting connection string in the web.config ACE2084 ADO.NET 2 January 6th, 2005 04:33 PM
Database Connection with Web.Config RPG SEARCH Classic ASP Databases 7 July 26th, 2004 06:10 PM
Variable Path in web.Config Connection String? ElPato General .NET 4 June 21st, 2004 05:44 PM



All times are GMT -4. The time now is 07:34 AM.


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