Entity framework gives error underlying provider failed on open - entity-framework

I developed a web site on my local pc and local database using entity framework, Now I gave all the code to my client now the entity framework gives an error underlying provider failed on open I modified data source, initial catalog, user id and password of the connection string of entity framework but of no use please help. below is my connection string.
<add name="SBV_dbEntities" connectionString="metadata=res://*/SBVEntityModel.csdl|res://*/SBVEntityModel.ssdl|res://*/SBVEntityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=yagnesh_db;user id=yagnesh;password=yagnesh#123;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

use like below.Give a connection string to the SQL server is as below (This is a sample code).
<add name="ContextName" connectionString="Data Source=ServerName;Initial Catalog=DBCatalogName;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
e.g.
<add name="PawLoyalty" connectionString="Server=.;database=PawLoyalty;Trusted_connection=true;pooling=true;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
I hope this will help to you.

Related

Entity Framework connection work locally but not on remote server after deploy

I have created a web application in ASP.NET MVC using a SQL Server database, and I used Entity Framework with a database-first approach.
This is my connection string for Entity Framework
<add name="AcModelFinalContext"
connectionString="metadata=res://*/Models.Maha-Earth-Model.csdl|res://*/Models.Maha-Earth-Model.ssdl|res://*/Models.Maha-Earth-Model.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-IE0U7PA\SQLEXPRESS;initial catalog=AC-Services;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
This connection string is working fine on localhost.
For deployment I made made changes in string as
<add name="AcModelFinalContext"
connectionString="metadata=res://*/Models.Maha-Earth-Model.csdl|res://*/Models.Maha-Earth-Model.ssdl|res://*/Models.Maha-Earth-Model.msl;provider=System.Data.SqlClient;provider connection string="data source=dburl.com\SQLEXPRESS;initial catalog=AC-Services;integrated security=True;User Id=mydb;Password=mypass;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
but this does not work.
Try to remove integrated security=True.
When you use this option, User/Password is not used.
You should also try to remove \SQLEXPRESS. I don't think your provider is using Sql-Server Express.

aEntities.savechange() not working

I'm using a Windows forms application with Entity Framework 5, all my model is constructed by entity (.edmx). That means for model creating it made a connection string in my app.config file:
<add name="PGDEntities"
connectionString="metadata=res://*/Model.ModelTest.csdl|res://*/Model.ModelTest.ssdl|res://*/Model.ModelTest.msl;provider=System.Data.SqlClient;provider connection string="data source=My-PC;initial catalog=DB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
My problem is that when I run my code on another computer then
aEntities = new PGDEntities();
aEntities.ModelName.Add(aModel);
aEntities.SaveChanges();
it throws an exception
An error occurred while updating the entries. See the inner exception for details.
It might be for the entity connection string, but I change my connection string to
<add name="PGDEntities"
connectionstring="metadata=res://*/Model.ModelTest.csdl|res://*/Model.ModelTest.ssdl|res://*/Model.ModelTest.msl;provider=System.Data.SqlClient;provider connection string="data source=MyOther-PC;initial catalog=DB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providername="System.Data.EntityClient" />
But it wouldn't go forward.
Can any one explain the problem or the solution. Because when I want to deploy it in user side then it will occur again for sure. I can't figure it out, please anyone help me

connection string to Postgres

I am new to Postgres and I need help with connection string.
My app using Entity Framework. I have this connectionString to MSSQL Server:
<connectionStrings>
<add name="DBContext" connectionString="Data Source=localhost;Initial Catalog=DB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
to my project i download a npgsql package (http://pgfoundry.org/projects/npgsql/) a need to help with editing connection string to Postgres database.
How to set providerName to npgsql?
Thank for help
"don't hard code your providers" discusses this in detail.
It shows a setting like what you want:
<add name="blah" providerName="Npgsql"
connectionString="Server=127.0.0.1;Port=5432;Database=myDataBase;
User Id=myUsername;Password=myPassword;"/>
but then explains why you should not do this, you should read the settings from your application's configuration file at runtime instead.

Entity Framework Code First Azure connection

I am using Entity Framework Code First 4.3 + Azure and having difficulties connecting to the database. The error I get is the following (on the first query):
Keyword not supported: 'server'.
I have the following connection set up in my Web.config
<configSections>
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="TestDBContext"
connectionString="Server=tcp:[SUBSCR].database.windows.net,1433;Database=[MyDB];User ID=[user];Password=[pass];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True"
providerName="System.Data.EntityClient" />
</connectionStrings>
My DbContext implementing class uses the connection string's name:
public class MyContext : DbContext, IMyContext
{
public MyContext()
: base("TestDBContext")
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
}
Can you tell what is going on?
I just had the same problem.
You're missing all the metadata in the connection string that Entity Framework requires. The connection string provided by SQL Azure needs to inserted within the provider connection string parameter of EF's connection string.
<add name="MyConnectionString" connectionString="metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string="[PUT SQL AZURE CONN STRING HERE]"" providerName="System.Data.EntityClient" />
You'll need to use the metadata from your own project. I pulled that metadata from an EF project generating from an existing database.
I had the same problem. I solved, putting in the web.config this connectionstring:
<add name="eManagerTurModelConnection" connectionString="metadata=res://*/ORM.eManagerFinanceModel.csdl|res://*/ORM.eManagerFinanceModel.ssdl|res://*/ORM.eManagerFinanceModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=<server>.database.windows.net;Initial Catalog=eManagerTur;Integrated Security=False;User ID=<user>;Password=<Password>;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
And after I removed the connectionstring of my website, worked, because it was not getting the connection string that I added in my web.config.
English bad... =)
The provider should be providerName="System.Data.SqlClient"
I connected to Azure from VS and then looked at the properties and set my connection string and provider name.
<add name="context" connectionString="Data Source=myServer,myPort;Initial Catalog=myDBName;Persist Security Info=True;User ID=myUserName;Password=myPassword;" providerName="System.Data.SqlClient"/>
I was then able to run update-database with no issues.
i tried like this, it may help you. may be 1433 is making problem, is it port no ? or what? . try like this.
check this link Windows Azure with Sql
<add name="dbContext" connectionString="Server=tcp:xxxxxxxx.database.windows.net;Database=xxxxxxxx;User ID=xxxxxxx#xxxxxxxxx;Password=xxxxxxxxxx;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.EntityClient" />
Try this:
Data Source=tcp:YOUR-DATABASE-HERE.database.windows.net,1433;
Database=GolfRounds;
User ID=YOUR-USERNAME#YOUR-SERVER; Password=YOUR-PASSWORD; Trusted_Connection=False; Encrypt=True;
There is also an MSDN article at http://msdn.microsoft.com/en-us/library/windowsazure/ff951633.aspx that may be helpful.
I had a similar problem where I did not have access to the metadata, in this case you need to use System.Data.SqlClient as the provider. You will also need to add MultipleActiveResultSets=True to your connection string

SQL Server Express connection string for Entity Framework Code First

I am working in Visual Web Developer 2010 Express, and using the Entity Framework code-first CTP. I am able to do this with the new SQL Server CE but I am unable to find a connection string to work with SQL Server Express.
This one, using the SQL Server CE beta, works fine (database is created and recreated on model changes).
<add name="TrempimModel"
connectionString="data source=|DataDirectory|TrempimModel.sdf"
providerName="System.Data.SqlServerCe.4.0" />
This one, which I copied from the aspnetdb connections string,
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|TrempimModel.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
Gives the following message on startup:
Unable to complete operation. The supplied SqlConnection does not specify an initial catalog
So how to make it work with SQL Server Express?
The problem with your connection string here is:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.sdf;
User Instance=true"
providerName="System.Data.SqlClient" />
You're basically defining what "server" you're connecting to - but you're not saying what database inside the file to connect to. Also - the file extension for SQL Server Express database files is .mdf (not .sdf - that's SQL Server Compact Edition) - you need to take that into account, too! (was a typo, according to comment by OP).
You need to define an extra database=.... (or Initial Catalog=.....) in your connection string:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
database=YourDatabaseName;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
Then it should work just fine.
For more background and tons of samples, check out the ConnectionStrings web site.