我决定将我的项目从工作转移到家,我在连接数据库时遇到了一些麻烦。这个工作起作用:
的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="esResearchModels.Properties.Settings.esResearchConnectionString2"
connectionString="Data Source=XXXXXX\SQLSERVER2008;Initial Catalog=esResearch;User ID=XXXXXX;Password=XXXXXX"
providerName="System.Data.SqlClient" />
</connectionStrings>
我想我不需要所有这些字符串,但它至少可以工作。这一行用于designer.cs
base(global::esResearchModels.Properties.Settings.Default.esResearchConnectionString2, mappingSource)
我已经在asp.net/mvc上完成了电影示例项目,并使用了这个连接字符串,这个可以在家里的电脑上运行。
的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>
有什么想法吗?
答案 0 :(得分:3)
有许多不同的连接字符串可用:
常规(Windows身份验证):
SqlConnection sql=new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=database;Integrated Security="True");
(SqlServer身份验证):
SqlConnection sql=new SqlConnection("Data Source=.\\SQLEXPRESS;Uid=sa;password=sqlserver;database=databasename");
如果您想了解有关连接字符串的更多信息,请访问:
http://www.connectionstrings.com