p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Hosting and the web.config file, connection string for Entity (http://p2p.wrox.com/showthread.php?t=88073)

jdlferreira July 22nd, 2012 07:33 PM

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?

Imar July 23rd, 2012 03:44 AM

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

sophia July 23rd, 2012 12:03 PM

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

jdlferreira July 23rd, 2012 01:01 PM

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?

Imar July 23rd, 2012 01:23 PM

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

jdlferreira July 23rd, 2012 01:49 PM

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.

Imar July 23rd, 2012 02:30 PM

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

jdlferreira July 23rd, 2012 02:49 PM

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

Imar July 23rd, 2012 03:28 PM

OK, so does it work now?

Imar

jdlferreira July 23rd, 2012 04:02 PM

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.


All times are GMT -4. The time now is 06:22 AM.

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