当我想访问ASP.NET配置工具时,它会给我以下错误消息:
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
我该怎么办?在我可以访问之前是否应该设置任何配置?
我正在使用带有内置连接字符串的ASP.Net MVC4项目。
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
答案 0 :(得分:0)
在继续操作之前,您应该从connection string
文件访问web.config
。
web.config文件:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
来自代码的 :访问位于web.config
文件
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;