Connection String in web.config fails to connect
I decided to transfer my project from work to home and I am having some trouble with the connection to the database. This one works on work:
web.config:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=XXXXXX\SQLSERVER2008;Persist Security Info=true;Initial Catalog=esResearch;User ID=XXXXXX; Password=XXXXXX"
providerName="System.Data.SqlClient" />
<add name="esResearchConnectionString" connectionString="Data Source=XXXXXX\SQLSERVER2008;Initial Catalog=esResearch;Persist Security Info=True;User ID=XXXXXX;Password=XXXXXX"
providerName="System.Data.SqlClient" />
</connectionStrings>
app.config:
<connectionStrings>
<add name="esResearchModels.Properties.Settings.esResearchConnectionString"
connectionString="Data Source=XXXXXX\SQLSERVER2008;Initial Catalog=esResearch;Persist Security Info=True;User ID=XXXXXX"
providerName="System.Data.SqlClient" />
<add name="esResearchModels.Properties.Settings.esResearchConnectionString1"
connectionString="Data Source=XXXXXX\SQLSERVER2008;Initial Catalog=esResearch;Persist Security Info=True;User ID=XXXXXX;Password=XXXXXX"
providerName="System.Data.SqlClient" />
<add name="esR开发者_高级运维esearchModels.Properties.Settings.esResearchConnectionString2"
connectionString="Data Source=XXXXXX\SQLSERVER2008;Initial Catalog=esResearch;User ID=XXXXXX;Password=XXXXXX"
providerName="System.Data.SqlClient" />
</connectionStrings>
I guess I do not need all those strings but it works atleast. And this line is used in designer.cs
base(global::esResearchModels.Properties.Settings.Default.esResearchConnectionString2, mappingSource)
I have done the movie sample project on asp.net/mvc and used this connectionstring and this one works on my computer at home.
Web.config:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;database=Movies;User ID=sa;password="
providerName="System.Data.SqlClient"/>
</connectionStrings>
Any ideas?
There are so many different connection strings are available:
General(Windows Authentication):
SqlConnection sql=new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=database;Integrated Security="True");
(SqlServer Authentication):
SqlConnection sql=new SqlConnection("Data Source=.\\SQLEXPRESS;Uid=sa;password=sqlserver;database=databasename");
If you want to know more about connection string, go to:
http://www.connectionstrings.com
精彩评论