问题:在建立与服务器的连接时出错

描述:

  在学习WebPartManager控件的使用时遇到了问题,总是失败。

  错误提示:

   A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

原因:

SqlException (0x80131904): 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)]

解决方法:

第一种方法是禁用个性化服务,修改WebPartManager的属性:Personalization -> Enabled 为 False

如果需要使用个性化服务,就得使用下面这个办法:
1. 运行 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe
按照提示安装数据库。

2. 在web.config文件的connectionStrings下加入一段连接字符串的配置:

Code
    <connectionStrings>
        
<remove name="LocalSqlServer"/>
        
<add name="LocalSqlServer" connectionString="user id=sa;password=sa;data source= 。;persist security info=True;initial catalog=AdventureWorks"/>    
    
</connectionStrings>

这段配置覆盖了默认的连接字符串,而使用自定义的。

OK,问题解决

参考:http://hi.baidu.com/gcc_gun/blog/item/2c9769f01cf479c27831aaf9.html

原文地址:https://www.cnblogs.com/icebutterfly/p/1497098.html