ASP.NET2.0 Login用户控件连接SQL Server 2000

2017 年 9 月 24 日3300

在ASP.NET 2.0中,提供了各类的provider,有membership、role、profile等等,甚至不用自己写代码就可以很方便地实现如角色、用户等管理。而在VS.NET 2005中,默认的各类的provider是使用SQL ServerExpress的,有的时候,如果想使用SQL Server 2000或者SQL Server 2005,那应该怎么办呢?下面举例子说明:

首先,要正确使用 provider,我们要到C:\WINNT\Microsoft.NET\Framework\v2.0.50215下,运行一个叫aspnet_regsql的工具,或者在Visual Studio 2005 命令提示中输入aspnet_regsql命令。之后按照其步骤设置就可以了,最后会产生一个叫aspnetdb的数据库。

在web.config中修改一下:

将原来的

<connectionStrings/>

替换成为

<connectionStrings>
<remove />
<add connectionString="Data Source=主机;Initial Catalog=数据库名;Persist Security Info=True;User ID=sa;Password=xxxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>

就可以了。

0 0