 |
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 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
|
|
|
|

July 22nd, 2012, 07:33 PM
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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?
|

July 23rd, 2012, 03:44 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

July 23rd, 2012, 12:03 PM
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
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="PlanetWroxConnectionString1;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
|
Many thanks
|

July 23rd, 2012, 01:01 PM
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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?
|

July 23rd, 2012, 01:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
Last edited by Imar; July 23rd, 2012 at 01:26 PM..
|

July 23rd, 2012, 01:49 PM
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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.
|

July 23rd, 2012, 02:30 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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 "'s (e.g. the provider connection stirng) and leave everything else in these.
Cheers,
Imar
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

July 23rd, 2012, 02:49 PM
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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...
|

July 23rd, 2012, 03:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
OK, so does it work now?
Imar
|

July 23rd, 2012, 04:02 PM
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |
|