I'm running ASP.NET MVC on a shared server and I'm having problems connecting to SQL via System.Data.EntityClient. Below is the connection string that my hosing provider gave me to connect to SQL and the one that VS configured for my local machine during development, what should my connection string look like when I deploy to the server?
From my hosting provider:
<add name="WeddingsDBEntities"
connectionString="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;"
providerName="System.Data.EntityClient"/>
From VS (during development):
connectionString="metadata=res://*/Models.WeddingsModel.csdl|res://*/Models.WeddingsModel.ssdl|res://*/Models.WeddingsModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\WeddingsDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"
Thanks!
The EntityClient provider is a data provider used by Entity Framework applications to access data described in a conceptual model. For information about conceptual models, see Modeling and Mapping. EntityClient uses other . NET Framework data providers to access the data source.
The first connection string, DefaultConnectionString, is used to describe the database that needs to be connected to from ASP.net pages. The second connection string, StandardConnectionString, is used by the Report Control in Report Center.
The Metadata parameter contains a list of locations for the EntityClient provider to search for model and mapping files. Model and mapping files are often deployed in the same directory as the application executable file.
You have to wrap the connection string instide an entity connection string which is in the format of
<add name="Name"
connectionString="metadata=<Conceptual Model>|<Store Model>|<Mapping Model>;
provider=<Underlying Connection Provider>;
provider connection string="<Underlying ConnectionString>""
providerName="System.Data.EntityClient"/>
Instead of:
<add name="WeddingsDBEntities"
connectionString="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;"
providerName="System.Data.EntityClient"/>
Use this:
<add name="WeddingsDBEntities"
connectionString="metadata=res://*/Models.WeddingsModel.csdl|res://*/Models.WeddingsModel.ssdl|res://*/Models.WeddingsModel.msl;provider=System.Data.SqlClient;provider connection string="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"/>
Change the provider from entityclient to sqlclient (assume code first EF).
providerName="System.Data.EntityClient" />
to
providerName="System.Data.SqlClient" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With