using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Security
{ public class ValidateBase : System.Web.UI.Page
{
private string sqlConnStr;
private SqlConnection conn;
public ValidateBase()
{
this.sqlConnStr = "Data Source=192.168.1.102;Initial Catalog=didian_data;User=sa;Password=sa;";
}
public ValidateBase(string connStr)
{
this.sqlConnStr = connStr;
}
private void Open()
{
if (this.conn == null)
this.conn = new SqlConnection(this.sqlConnStr);
if (this.conn.State == ConnectionState.Closed)
this.conn.Open();
}
private void Close()
{
if (this.conn.State == ConnectionState.Open)
this.conn.Close();
if (this.conn != null)
this.conn.Dispose();
this.conn = null;
}
public void BuildParameters(SqlParameter[] param, ref SqlCommand comm)
{
//若参数不为空,则添加到命令对象
if (param != null)
{
foreach (SqlParameter par in param)
comm.Parameters.Add(par);
}
//添加返回参数
comm.Parameters.Add(new SqlParameter("returnvalue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, true, 0, 0, string.Empty, DataRowVersion.Default, 0));
return;
}
public void ExecuteProcedure(string proceName, SqlParameter[] param, ref DataSet ds)
{
//打开连接
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = proceName;
comm.CommandType = CommandType.StoredProcedure;
this.BuildParameters(param, ref comm);
//初始化adapter对象
SqlDataAdapter ada = new SqlDataAdapter(comm);
//返回ds
ada.Fill(ds);
//关闭连接
this.Close();
return;
}
public void ExecuteProcedureInsertInto(string proceName, SqlParameter[] param)
{
//打开连接
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = proceName;
comm.CommandType = CommandType.StoredProcedure;
this.BuildParameters(param, ref comm);
comm.ExecuteNonQuery();
//关闭连接
this.Close();
//return;
}
public bool check_username(string procedurename, SqlParameter[] parm)
{
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = procedurename;
comm.CommandType = CommandType.StoredProcedure;
this.BuildParameters(parm, ref comm);
return Convert.ToBoolean(comm.ExecuteScalar());
this.Close(); } public void Executeprocedure(string procedurename, ref DataSet ds)
{
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = procedurename;
comm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(comm);
ada.Fill(ds);
this.Close(); }
public SqlDataReader Executeprocedure1(string procedurename)
{
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = procedurename;
comm.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = comm.ExecuteReader();
return dr;
this.Close(); }
public SqlDataReader ExecuteProcedure(string proceName, SqlParameter[] param)
{ //打开连接
//int num;
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = proceName;
comm.CommandType = CommandType.StoredProcedure; this.BuildParameters(param, ref comm);
//SqlDataReader dr = comm.ExecuteReader();
//news = dr.GetValue(1).ToString();
SqlDataReader dr = comm.ExecuteReader(); // num = Convert.ToInt32(comm.ExecuteScalar());
//if(dr.Read())
return dr;
// Response.Write("<script>alert('"+dr.GetString(1)+"');</script>"); //关闭连接
this.Close(); }
public void datab(string sql, ref DataSet ds)
{
this.Open();
//OleDbCommand comm = new OleDbCommand(sql,this.OledbConn);
SqlDataAdapter adap = new SqlDataAdapter(sql, this.conn);
adap.Fill(ds);
this.Close();
return;
} public SqlDataReader readrow(string sqlstr1)
{
SqlConnection datareaderconn = new SqlConnection(this.sqlConnStr);
SqlCommand datareadercomm = new SqlCommand(sqlstr1, datareaderconn);
SqlDataReader datareader;
datareadercomm.Connection.Open();
datareader = datareadercomm.ExecuteReader(); if (datareader.Read())
{
datareadercomm.Dispose();
return datareader;
}
else
{
datareadercomm.Dispose();
return null;
}
}
/// <summary>
/// 存放验证码值
/// </summary>
public string strValidate
{
get
{
if (Session["ValidateCode"] != null)
return Session["ValidateCode"].ToString();
else
return "";
}
set
{
Session["ValidateCode"] = value;
}
}
/// <summary>
/// 存放登入信息
/// </summary>
public string strUser
{
get
{
if (Session["strUser"] != null)
return Session["strUser"].ToString();
else
return "";
}
set
{
Session["strUser"] = value;
}
}
}
}出现问题:
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Security
{ public class ValidateBase : System.Web.UI.Page
{
private string sqlConnStr;
private SqlConnection conn;
public ValidateBase()
{
this.sqlConnStr = "Data Source=192.168.1.102;Initial Catalog=didian_data;User=sa;Password=sa;";
}
public ValidateBase(string connStr)
{
this.sqlConnStr = connStr;
}
private void Open()
{
if (this.conn == null)
this.conn = new SqlConnection(this.sqlConnStr);
if (this.conn.State == ConnectionState.Closed)
this.conn.Open();
}
private void Close()
{
if (this.conn.State == ConnectionState.Open)
this.conn.Close();
if (this.conn != null)
this.conn.Dispose();
this.conn = null;
}
public void BuildParameters(SqlParameter[] param, ref SqlCommand comm)
{
//若参数不为空,则添加到命令对象
if (param != null)
{
foreach (SqlParameter par in param)
comm.Parameters.Add(par);
}
//添加返回参数
comm.Parameters.Add(new SqlParameter("returnvalue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, true, 0, 0, string.Empty, DataRowVersion.Default, 0));
return;
}
public void ExecuteProcedure(string proceName, SqlParameter[] param, ref DataSet ds)
{
//打开连接
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = proceName;
comm.CommandType = CommandType.StoredProcedure;
this.BuildParameters(param, ref comm);
//初始化adapter对象
SqlDataAdapter ada = new SqlDataAdapter(comm);
//返回ds
ada.Fill(ds);
//关闭连接
this.Close();
return;
}
public void ExecuteProcedureInsertInto(string proceName, SqlParameter[] param)
{
//打开连接
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = proceName;
comm.CommandType = CommandType.StoredProcedure;
this.BuildParameters(param, ref comm);
comm.ExecuteNonQuery();
//关闭连接
this.Close();
//return;
}
public bool check_username(string procedurename, SqlParameter[] parm)
{
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = procedurename;
comm.CommandType = CommandType.StoredProcedure;
this.BuildParameters(parm, ref comm);
return Convert.ToBoolean(comm.ExecuteScalar());
this.Close(); } public void Executeprocedure(string procedurename, ref DataSet ds)
{
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = procedurename;
comm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(comm);
ada.Fill(ds);
this.Close(); }
public SqlDataReader Executeprocedure1(string procedurename)
{
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = procedurename;
comm.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = comm.ExecuteReader();
return dr;
this.Close(); }
public SqlDataReader ExecuteProcedure(string proceName, SqlParameter[] param)
{ //打开连接
//int num;
this.Open();
SqlCommand comm = this.conn.CreateCommand();
comm.CommandText = proceName;
comm.CommandType = CommandType.StoredProcedure; this.BuildParameters(param, ref comm);
//SqlDataReader dr = comm.ExecuteReader();
//news = dr.GetValue(1).ToString();
SqlDataReader dr = comm.ExecuteReader(); // num = Convert.ToInt32(comm.ExecuteScalar());
//if(dr.Read())
return dr;
// Response.Write("<script>alert('"+dr.GetString(1)+"');</script>"); //关闭连接
this.Close(); }
public void datab(string sql, ref DataSet ds)
{
this.Open();
//OleDbCommand comm = new OleDbCommand(sql,this.OledbConn);
SqlDataAdapter adap = new SqlDataAdapter(sql, this.conn);
adap.Fill(ds);
this.Close();
return;
} public SqlDataReader readrow(string sqlstr1)
{
SqlConnection datareaderconn = new SqlConnection(this.sqlConnStr);
SqlCommand datareadercomm = new SqlCommand(sqlstr1, datareaderconn);
SqlDataReader datareader;
datareadercomm.Connection.Open();
datareader = datareadercomm.ExecuteReader(); if (datareader.Read())
{
datareadercomm.Dispose();
return datareader;
}
else
{
datareadercomm.Dispose();
return null;
}
}
/// <summary>
/// 存放验证码值
/// </summary>
public string strValidate
{
get
{
if (Session["ValidateCode"] != null)
return Session["ValidateCode"].ToString();
else
return "";
}
set
{
Session["ValidateCode"] = value;
}
}
/// <summary>
/// 存放登入信息
/// </summary>
public string strUser
{
get
{
if (Session["strUser"] != null)
return Session["strUser"].ToString();
else
return "";
}
set
{
Session["strUser"] = value;
}
}
}
}出现问题:
解决方案 »
- 用动软.net代码生成器生成的 model 一些不解。private DateTime? _resultdate;
- 关于IP鉴权怎么做?
- 登陆基础问题,学习~!
- 我引用了水晶报表。但网站的bin并没水晶报表的dll ,发布到服务器上报错。水晶报表的dll在那里。怎样加到项目中?
- Label的值隨著程序的執行不斷變化!如何將這個變化的隻實時顯示在客戶端的瀏覽器上面?
- ASP.NET Ajax的问题
- 我在一个页面上放了100个textbox,会不会很慢 有谁有过这样的经验
- 求一个免费的分页的控件.谢谢(有就是结账)
- 大家有用.NET操作Excel表格的时候吗?有没有遇到Excel关不了这样的问题!
- 什么原因?怎么解决?
- 请教大师们,读取cookie都是乱码,应该怎么办?.net可以解码吧
- radiobuttonlist很奇怪的问题
打开MSSQLSERVER节点下的Database Engine节点,选择"远程连接",接下来建议选择”同时使用TCP/IP和named pipes ”,确定后,重启数据库服务.
如果已经设置了 windows与SQL Server混合验证且启用了sa帐户
在开始菜单中的"SQL SERVER 2005"->"Configuration Tools"->"SQL SERVER Configuration Management"中将"SQL SERVER Clinet"中的命名管道(named pipes)打开,然后重启一下SQL SERVER的服务
防火墙是否设置.端口号是否禁用,企启用1433端口
或在页面放置一个sqlconnection,然后通过.net的配置程序,配置一个,看看里面的连接字符串
connectionString="Data Source==.\SQLEXPRESS;Initial Catalog=;User ID=sa;Password=sa"