i am new to EF ...
getting this error while adding another edmx in same project
using same connection string .
this is my connection string
<add name="REFLECTIONDBEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="data source=SERVER;initial catalog=REFLECTIONDB;persist security info=True;user id=sa;password=Sqlsa123;multipleactiveresultsets=True;application name=EntityFramework"" />
Same connection Strings Names are not allowed, you can have multiple Connection Strings but with separate names.
Change
name="REFLECTIONDBEntities"
To
name="REFLECTIONDBEntities2"
Related
I am facing problem when I am using two connection string in my web.config file.
One connection string is simple DefaultDBConnection which is used for account controller.
Another connection is EntitiesConnection string Database first approach. This connection string is used to process SELECT operation using my stored procedure and this connection string is completely used in separate controller.
When i use both the connection string. Only EntitiesConnection string works and the operations on account controller does not work.
Can any one help me to fix this. I have been searching from past two days but unfortunately i did not find any solution.
Below is my two connection string in web.config.
<add name="DefaultDBConnection" connectionString="Data Source=xyz;Initial Catalog=My_DB;User ID=abc;pwd=abc123" providerName="System.Data.SqlClient" />
<add name="EntitiesConnection" connectionString="metadata=res://*/EntityModel.Model1.csdl|res://*/EntityModel.Model1.ssdl|res://*/EntityModel.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=xyz;initial catalog=My_DB;user id=abc;password=abc123;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
swap the names in the config make DefaultDBConnection ==EntitiesConnection and EntitiesConnection ==DefaultDBConnection
Check identityModel.cs file in the models folder, whether base name is same as the connection string name,
public ApplicationDbContext()
: base("DefaultDBConnection", throwIfV1Schema: false)
{
}
In the web config;
<add name="DefaultDBConnection" connectionString="Data Source=xyz;Initial
Catalog=My_DB;User ID=abc;pwd=abc123" providerName="System.Data.SqlClient" />
I have created a database first mvc project that gave me a default connection string in my web.config file.
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\BETADB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Now I need to connect my project to the server database. Connection string:
<add name="name" connectionString="Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
When I change the connection string and run I get the following error:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
Replace the original connection string you had under 'provider connection string' with the new one from the server:
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="(your connection string here)"" providerName="System.Data.EntityClient" />
Resulting in this connection string:
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true"" providerName="System.Data.EntityClient" />
I created a Black Solution (Arhi) with a ASP.NET MVC 4 Internet project (Arhi.Core) and Class library project for data (Arhi.Data) where I'm storing my EDMX Model.
I added a reference for Arhi.Data into Arhi.Core and I tried to add a Controller with a Model class from Arhi.Data (People entity) and I got this error.
'Unable to retrive metadata for 'Arhi.Core.People'. The specified
named connection is either not found in the configuration, not
inteneded to be used with the EntityClient provider, or not valid.'
Q : Why did I get this error ? Is my approach wrong / any recommendations?
Q2 : If I want to add RDLC reports to my solution, should I also use a Class Library project ?
Connection string from Arhi.Core
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-SalvamontMVC-20121108140556;Integrated Security=SSPI" />
and Arhi.Data
<add name="SalvamontEntities" connectionString="metadata=res://*/ModelSalva.csdl|res://*/ModelSalva.ssdl|res://*/ModelSalva.msl;provider=System.Data.SqlClient;provider connection string="data source=www.arhimedes.ro,1433;initial catalog=Salvamont;persist security info=True;user id=sa;password=********;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
in your first connection string not have user name and password if two database deference then give user name and password in first connection string
I'm working on an mvc .net application and I'm using Entity Framework. I have the same database in different servers and I want to change the current server. I tried to change the connection string in the web.config file but it didn't work. How to safely change the server?
You must replace Data Source
<connectionStrings>
<add
name="AdventureWorksEntities"
connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
provider=System.Data.SqlClient;
provider connection string='Data Source=.....;
Initial Catalog=....;
Integrated Security=True;
Connection Timeout=60;
multipleactiveresultsets=true'"
providerName="System.Data.EntityClient" />
</connectionStrings>
Changing the connection string in web.config is all you need to do.
Make sure you are changing the right connection string (the one with the metadata). Entity Framework will automatically put a connection string in the web.config when the model is first created.
The correct connection string will look something like this:
<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" />
I'm doing a Model first approach for a Microsoft MVC application. The solution is named "TutorialPile" divided into two projects, Domain and WebUI. I try to add a controller for the Tutorial object to the WebUI project, and I select the domain class and the DB context. However, I get the error, "Unable to retrieve metadata for TutorialPile.Tutorial. Unable to load the specified metadata resource."
Looking around online it looks like it can't find the edmx object in the connection string in the web.config file. I copied the connection string from the Domain project's app.config file but it still doesn't work. Here are the connection strings from the web.config file.
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="TutorialPileModelContainer" connectionString="metadata=res://*/Models.TutorialPileModel.csdl|res://*/Models.TutorialPileModel.ssdl|res://*/Models.TutorialPileModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=TutorialPileDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="TutorialPileDbContext" connectionString="metadata=res://*/Models.TutorialPileModel.csdl|res://*/Models.TutorialPileModel.ssdl|res://*/Models.TutorialPileModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=TutorialPileDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
And here is the connection string that I copied.
<add name="TutorialPileDBEntities" connectionString="metadata=res://*/TutorialPile.csdl|res://*/TutorialPile.ssdl|res://*/TutorialPile.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=TutorialPileDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Any ideas on what I need to change?
Make sure...
the edmx file's build action is set to EntityDeploy (select the file and go to the properties window).
Your WebUI project references the Domain project
Edit the connection string on your WebUI project to reference the metadata from the other project. Using * means it can come from any dll. BUT, if your edmx file is inside a folder, you have to map the hierarchy.
Eg:
Path to EDMX: TutorialPile.Domain/Model/TutorialPile.edmx
Connection string: res://*/Model.TutorialPile.csdl|res://*/Model.TutorialPile.ssdl|res://*/Model.TutorialPile.msl
Even better:
The documentation suggests you specify the assembly (for performance reasons) using the full name of the assembly (something like: AdventureWorks, 1.0.0.0, neutral, a14f3033def15840). I couldn't make it work. But, using only the name of the assembly works for me. So, if your domain project outputs a TutotialPile.Domain.dll, you can use:
res://TutorialPile.Domain/Model.TutorialPile.csdl|res://TutorialPile.Domain/Model.TutorialPile.ssdl|res://TutorialPile.Domain/Model.TutorialPile.msl