views:

1606

answers:

1

Hello, 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!

+3  A: 

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=&quot;<Underlying ConnectionString>&quot;" 
  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=&quot;data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;MultipleActiveResultSets=True&quot;" 
  providerName="System.Data.EntityClient"/>
bendewey
Thanks. Ok, so that worked, although now I'm getting a error 500 - "There is a problem with the resource you are looking for, and it cannot be displayed.". Could there be something wrong with the res:// paths? why do they start with '*/' ?
Birdman
Did you replace out the datasource, dbname, userid, and password?
bendewey
Try taking off the last part of the provider connection string that says MultipleResultSets=true;
bendewey