将 ASP.NET 2.0 应用程序服务配置为使用 SQL Server 2000 或 SQL Server 2005(转)

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
-----------------------------------------------------------------------------------------------------------------------------------------------

在使用VS2005+MS-SqlServer2000进行开发的时候可能经常回遇到以上错误,如何能解决呢?请看

我的实践是machine.config里和项目模版里自动把数据库指定为 .\sqlexpress ,我明明没有装express啊。好了知道问题所在。

找到2.0带的machine.config在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG下,找到<connectionStrings>节,将里面的内容改为: 
<connectionStrings>
  <add name="LocalSqlServer" connectionString="data source=.;Integrated

  Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"

  sproviderName="System.Data.SqlClient"/>

</connectionStrings>


问题解决了实在不行就按下面的来做!

总结一下最后的方案:

1、打开vs自带的命令行窗口,运行aspnet_regsql.exe,按提示操作,在sql2005里建立了一个名为aspnetdb的数据库,右键点数据库aspnetdb-->新查询,在项目路径下App_data里有个personal-add.sql,里面内容复制粘贴到新查询里,运行,这样在aspnetdb里加入了程序需要的表结构;

2、找到2.0带的machine.config在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG下,找到<connectionStrings>节,将里面的内容改为: 
<connectionStrings>
    <add name="LocalSqlServer" connectionString="data source=.;Integrated Security=SSPI;Initial Catalog=aspnetdb;" providerName="System.Data.SqlClient" />
  </connectionStrings>
打开项目下的web.config,改<connectionStrings>节为:
 <connectionStrings>
  <add name="Personal" connectionString="Data Source=.;Initial Catalog=aspnetdb;Integrated Security=True;" providerName="System.Data.SqlClient" />
  <!--<add name="LocalSqlServer" connectionString="Data Source=.;Initial Catalog=aspnetdb;Integrated Security=True;" providerName="System.Data.SqlClient" />-->
 </connectionStrings>

ok,运行!

不知道为什么,machine.config里和项目模版里自动把数据库指定为 .\sqlexpress ,我明明没有装express啊。还有我用sqlprovider联接到它自带的personal.mdf 数据库,总提示我remote access失败,我明明把tcp/ip方式打开了。(我在另一台机器上装了sqlexpress,不打开tcpip方式,提示出错信息一样,打开tcpip就可以)

----继续研究2.0吧

posted @ 2011-07-12 14:33  plccs  阅读(192)  评论(0编辑  收藏  举报