1、webconfig链接数据库
<appSettings>
<add key="标记名称" value="
server=服务器名称;
uid=登录名;
pwd=密码;
database=数据库名称"/>
</appSettings>
C#得到:System.Configuration.ConfigurationManager.AppSettings["标记名称"].ToString()
或
<connectionStrings>
<add name="标记名称" connectionString="server=服务器名称;
uid=登录名;
pwd=密码;
database=数据库名称"/>
</connectionStrings>
C#得到:System.Configuration.ConfigurationManager.ConnectionStrings["标记名称"].ToString()
2、登录成功创建或删除身份票证(写入或删除session)
System.Web.Security.FormsAuthentication.SetAuthCookie(name.Text, true);
System.Web.Security.FormsAuthentication.SignOut();
User.Identity.IsAuthenticated //验证是否创建身份票证
3、SQL语句得到执行时间小技巧(对数据库优化后得到效果)
SET STATISTICS IO ON
declare @d datetime
set @d=getdate()
------------select 字段 ----------这里是要执行的SQL语句
select [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate())