Pre-Generating views to improve query performance in Entity Framework - asp.net

I am trying to pre-generate view metadata for my Entity Framework project and have run across a problem on the last step when using this resource:
http://msdn.microsoft.com/en-us/library/bb896240.aspx
Everything else is compiling great, but I'm getting an error when I run my application, and I suspect it's due to a problem with the final step, 're-adding mapping and model files as embedded resources for ASP.NET projects.'
I'm receiving 'Unable to load the specified metadata resource.' and my connection string is as follows:
<add name="myEntities"
connectionString="metadata=
.\DataStructure.csdl|
.\DataStructure.ssdl|
.\DataStructure.msl;provider=System.Data.SqlClient;provider
connection string="Data Source=x;Initial Catalog=x;Persist Security Info=True;User ID=x;Password=x;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
It is suggested in the document that my connection string file should include the following but haven't been able to get it right in any configuration:
Metadata=res://<assemblyFullName>/<resourceName>;
Metadata=res://*/<resourceName>;
Metadata=res://*;
Assuming my assembly name is DataStructure.EF, how should my string be constructed?

http://msdn.microsoft.com/en-us/library/cc716756.aspx
<connectionStrings>
<add name="AdventureWorksEntities"
connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
</connectionStrings>

I compiled a full guide for anybody else having problems and published it here: http://kewney.com/posts/software-development/pre-generating-views-to-improve-query-performance-in-aspnet-mvc-3-entity-framework

Related

Connection Strings- smarterasp.net

Can anyone help me with this? Ive been getting tons of errors. I know there's probably just a syntax error here somewhere, but I'm not sure if I'm doing it right.
this is the connection string that was given to me by smarterasp: "Data Source=SQL5006.Smarterasp.net;Initial Catalog=DB_9B7F44_capstone;User Id=DB_9B7F44_capstone_admin;Password=YOUR-PASSWORD;"
this was my connection string on my local machine:
<connectionStrings> <add name="d_CapstoneEntities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=WIN-C43BMU8UF5E\SQLEXPRESS;initial catalog=d_Capstone;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
and then I came up with this, but im still getting the error "Keyword not supported: 'data source'."
<add name="d_CapstoneEntities1" providerName="System.Data.EntityClient" connectionString="Data Source=SQL5006.Smarterasp.net;Initial Catalog=DB_9B7F44_capstone;User Id=DB_9B7F44_capstone_admin;Password=YOUR-PASSWORD;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;"/></connectionStrings>
I used the EF database first btw.

Entity Framework connection string issue

I am receiving the following error which I believe is a problem with my connection string on GoDaddy. I've copied from an example on Stack Overflow, but it doesn't seem to work. The first part of the stack trace that I'm getting is:
[MetadataException: Unable to load the specified metadata resource.]
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String
assemblyName, String resourceName, ICollection`1 uriRegistry,
MetadataArtifactAssemblyResolver resolver) +2184231
I have a solution with only one project and, of course, the edmx is in that project.
Here is my connection string:
<add name="FCGUIDE_Entities"
connectionString="
metadata=res://*/CoreModel.csdl|res://*/CoreModel.ssdl|res://*/CoreModel.msl;
provider=System.Data.SqlClient;
provider connection string='
Data Source=susanbfarrar.db.9319451.hostedresource.com;
Initial Catalog=susanbfarrar;
integrated security=False;
multipleactiveresultsets=True;
App=EntityFramework;
User ID=*****;
Password=*****
Database=*****;'"
providerName="System.Data.EntityClient" />
Could you replace ' with " and try it again?
<add name="FCGUIDE_Entities"
connectionString="
metadata=res://*/CoreModel.csdl|res://*/CoreModel.ssdl|res://*/CoreModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=susanbfarrar.db.9319451.hostedresource.com;
Initial Catalog=susanbfarrar;
integrated security=False;
multipleactiveresultsets=True;
App=EntityFramework;
User ID=*****;
Password=*****
Database=*****;""
providerName="System.Data.EntityClient" />
You already have Initial Catalog, so remove Database
Password=*****Database=*****;"
Like this -
Password=*****;"

Have connection strings as well as common config source in asp.net or wcf websites

Hi I am looking for a solution where I have some common connection strings which I have
a common connections strings file but also need some specific add and remove connection strings in some sites...but do not see a way to do it...
<configuration>
<connectionStrings configSource="connections.config">
<remove name="AppConnectionString" />
<add name="AppConnectionString" connectionString="data source=(local);initial catalog=xyz;integrated security=True;MultipleActiveResultSets=True;" />
<connectionStrings/>
</configuration>
With file connections.config containing
<connectionStrings>
<add name="name" connectionString="conn_string" providerName="System.Data.SqlClient" />
<add name="name2" connectionString="conn_string2" providerName="System.Data.SqlClient" />
</connectionStrings>
Thanks,
Bala
If this does not work as you have expressed it above (which is a shame in my opinon), you have a number of other options:
Include the common connection strings in the connection string config, and then use the application settings config for the app-specific connection strings.
As an alternative, use a custom configuration file for the app-specific connection strings and load it in for each app.
When you build your apps inject the correct connection string keys into the config file using something like powershell. This script can run as a post build task in your build script.
Otherwise, when you package or stage your release, ask the release team to run the script as a manual step (or add it into your deployment script).

ASP.NET Attempt to attach auto-named a database failed?

Parser Error Message: An attempt to
attach an auto-named database for file
D:\Projects\Damnation\Damnation.Website\Damnation.Website.Tracker\BugNET_WAP\App_Data\aspnetdb.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
Why could this be happening? My connection string doesn't use |DataDirectory|, it is:
<connectionStrings>
<add name="BugNET" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dnmain;Integrated Security=True;"/>
</connectionStrings>
I get this error when I try to load default.aspx, after installing BugNET.
Apparently, and certainly for some obscure reason. There is a mistery connection string coming from... nowhere.
Problem solved adding a <clear/> tag.
<connectionStrings>
<clear/>
<add name="BugNET" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dnmain;Integrated Security=True;"/>
</connectionStrings>
file
D:\Projects\Damnation\Damnation.Website\Damnation.Website.Tracker\BugNET_WAP\App_Data**aspnetdb.mdf**
failed.
This is the ASP.NET standard membership system here - not your "regular" database. There must be a second connection string somewhere that references this aspnetdb.mdf and tries to attach it from a file.
Search your solution for this file name - it must be somewhere!

Membership provider name and type for Microsoft WebMatrix's sample Template

What is the membership provider name and type is used in the Microsoft Webmatrix's template site? In the web.config it is not given. When I run it locally, the template works but when I publish, it gives the following error:
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error:
Line 239: <providers>
Line 240: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, ....
Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config Line: 240
Any help will be appreciated.
The Database used in the application is SQLCE4.
Web Pages uses the SimpleMembershipProvider which is located in WebMatrix.WebData.
I don't believe there's a default Membership provider that supports SQL Server Compact Edition 4. There is a Membership provider implementation that does out on CodePlex: http://sqlcemembership.codeplex.com/
So, if you're using that already, then ensure that you have a connection string defined in your config file, like so:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="data source=|DataDirectory|\YourDatabaseName.sdf"/>
</connectionStrings>
And your provider specified in your config should define the connectionStringName attribute and reference the connection string's name defined in the <connectionStrings> block, like this:
<providers>
<clear/>
<add name="SqlCeMembershipProvider"
type="ErikEJ.SqlCeMembershipProvider"
connectionStringName="LocalSqlServer"
.... />
</providers>
A config sample is provided with that SQL CE 4 Membership provider on the main project page.

Resources