<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>
由于本人机器上仅安装SQLSERVER2005,而没有装SQLSERVER EXPRESS,于是在部署user profile时遇到了aspnetdb.mdf无法连接的问题,经过一番折腾
,总算解决了,下面把经验写下来与大家分享。
由于没有aspnetdb.mdf数据库,因此得先建立一个,这个可以通过aspnet_regsql.exe完成,该程序位于C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\下。运行它之后会弹出 [图1] 的窗口:
图1
按"Next >"按钮,进入图2
图2
在图2中,我们会发现除了有配置数据库外,还有删除数据库的功能,以后说不定可以派上用场,现在自然选Configure SQL Server for application services,按"Next >"按钮,进入图3。
图3
现在进入数据库选择界面,如果SQLSERVER就安装在本地的话,可以不用改任何东西,直接按"Next >"。这里的Database显示为<default>,表示默认数据库名为aspnetdb,你也可以根据自己的需要更改名称。<br><img alt="" src="http://tonyqus.cnblogs.com/images/cnblogs_com/tonyqus/42519/o_Capture_4.jpg"><br> 图4<br>最后进入图4,现在按"Next >"就可以开始安装数据库了,当Finish按钮亮起时,表明数据库安装成功,一切顺利!<br><br>接下来是设置数据库连接字符串。<br>默认情况下,web.config中的LocalSqlServer属性是这样配置的:<br><div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"> <!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: rgb(0,0,255)"><span style="COLOR: rgb(128,0,0)">connectionStrings</span><span style="COLOR: rgb(0,0,255)">></span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,0,255)"><span style="COLOR: rgb(128,0,0)">add</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="LocalSqlServer"</span><span style="COLOR: rgb(255,0,0)">connectionString</span><span style="COLOR: rgb(0,0,255)">="DataSource=./SQLExpress;IntegratedSecurity=true;AttachDBFileName=|DataDirectory|aspnetdb.mdf;UserInstance=True"</span><span style="COLOR: rgb(255,0,0)"> <br>providerName</span><span style="COLOR: rgb(0,0,255)">="System.Data.SqlClient"</span><span style="COLOR: rgb(0,0,255)">/></span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,0,255)"></span><span style="COLOR: rgb(128,0,0)">connectionStrings</span><span style="COLOR: rgb(0,0,255)">></span></span></span> </div>该连接字符串是专门为SQLSERVER EXPRESS准备的,如果没有安装SQLSERVER EXPRESS就会出现以下错误<br><span></span><h2 style="COLOR: rgb(128,0,0)"><font size="3"><i><i>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)</i></i></font></h2>这表明连接根本无法建立。为此,我试图把DataSource改为./本地sqlserver instance名,结果还是报错:<br><font size="3"><span style="FONT-WEIGHT: bold; COLOR: rgb(128,0,0)">Login Failed for User </span></font><font style="FONT-WEIGHT: bold; COLOR: rgb(128,0,0)" size="3">MachineName\ASPNET</font><br><span></span><h2 style="FONT-WEIGHT: normal; COLOR: rgb(0,0,0)"><font size="3">又试图把User Instance设为false,再次报错:<img alt="" src="http://tonyqus.cnblogs.com/Emoticons/hitwall.gif" align="middle" border="0"></font></h2> <h2 style="COLOR: rgb(128,0,0)"><font size="3"><i><i>Invalid value for key 'attachdbfilename'.</i></i></font></h2>其实出错原因很简单,因为App_Data目录下没有aspnetdb.mdf这个文件。在网上查了一下,终于找到了解决方法,重新设置连接字符串为<br><div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"> <!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: rgb(0,0,255)"><span style="COLOR: rgb(128,0,0)">add</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="LocalSqlServer"</span><span style="COLOR: rgb(255,0,0)">connectionString</span><span style="COLOR: rgb(0,0,255)">="DataSource=[Instance Name];InitialCatalog=aspnetdb;IntegratedSecurity=false;UID=sa;PWD=xxxxxx"</span></span> </div> <a href="http://tonyqus.cnblogs.com/archive/2005/12/02/weblogs.asp.net/bsimser/archive/2005/11/20/431029.aspx?Pending=true" target="_blank"></a><br>其实就是标准SqlServer连接字符串,郁闷……<br><br>本文来自<br><a href="http://tonyqus.cnblogs.com/archive/2005/12/02/288886.html">http://tonyqus.cnblogs.com/archive/2005/12/02/288886.html</a><a href="http://tonyqus.cnblogs.com/archive/2005/12/02/weblogs.asp.net/bsimser/archive/2005/11/20/431029.aspx?Pending=true" target="_blank"></a><br><br><br><br></default>