| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 960 人关注过本帖
标题:[求助]关于使用自定义membership连接数据库
只看楼主 加入收藏
luzihui
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-11
收藏
 问题点数:0 回复次数:1 
[求助]关于使用自定义membership连接数据库


我弄的是连接到access,但是创建不了数据库!请大家帮帮忙啊,谢谢!!
public class AccessMembershipProvider : MembershipProvider
{
private string connStr;

private bool _requiresQuestionAndAnswer;
private int _minRequiredPasswordLength;

public AccessMembershipProvider()
{
//
// TODO: Add constructor logic her
//
}

public override int MinRequiredPasswordLength
{
get { return _minRequiredPasswordLength; }
}
public override bool RequiresQuestionAndAnswer
{
get
{
return _requiresQuestionAndAnswer;
}
}

public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
if (config["requiresQuestionAndAnswer"].ToLower() == "true")
{
_requiresQuestionAndAnswer = true;
}
else
{
_requiresQuestionAndAnswer = false;
}
int.TryParse (config["minRequiredPasswordLength"],out _minRequiredPasswordLength );
connStr = config["connectionString"];
base.Initialize(name, config);
}

public override bool ValidateUser(string username, string password)
{

System.Data.OleDb.OleDbConnection conn=new System.Data.OleDb.OleDbConnection(connStr);
try
{
conn.Open();
string sql = "select * from Membership where username=@username and password=@password";
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(sql, conn);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
System.Data.OleDb.OleDbDataReader reader = command.ExecuteReader();

if (reader.HasRows)
{
conn.Close();
return true;
}
else
{
conn.Close();
return false;
}

}
catch
{
if (conn.State == ConnectionState.Open)
conn.Close();
return false;
}

}

public override string ApplicationName
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}

public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new Exception("The method or operation is not implemented.");
}

public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new Exception("The method or operation is not implemented.");
}

public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connStr);
try
{
conn.Open();
string sql = "insert into Membership(username,password,Email,passwordQuestion,passwordAnswer) values(@username,@password,@Email,@passwordQuestion,@passwordAnswer)";
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(sql, conn);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
command.Parameters.AddWithValue("@Email", email);
command.Parameters.AddWithValue("@passwordQuestion", passwordQuestion);
command.Parameters.AddWithValue("@passwordAnswer", passwordAnswer);
command.ExecuteNonQuery();
MembershipUser user = new MembershipUser("AccessMembershipProvider", username, providerUserKey, email, passwordQuestion, "", isApproved, true, DateTime.Now, DateTime.Now , DateTime.Now, DateTime.Now, DateTime.Now);
status = MembershipCreateStatus.Success;
return user;

}
catch
{
if (conn.State == ConnectionState.Open)
conn.Close();
status = MembershipCreateStatus.ProviderError;
return null;
}
}

public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new Exception("The method or operation is not implemented.");
}

public override bool EnablePasswordReset
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override bool EnablePasswordRetrieval
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}

public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}

public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}

public override int GetNumberOfUsersOnline()
{
throw new Exception("The method or operation is not implemented.");
}

public override string GetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}

public override MembershipUser GetUser(string username, bool userIsOnline)
{
throw new Exception("The method or operation is not implemented.");
}

public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
throw new Exception("The method or operation is not implemented.");
}

public override string GetUserNameByEmail(string email)
{
throw new Exception("The method or operation is not implemented.");
}

public override int MaxInvalidPasswordAttempts
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override int MinRequiredNonAlphanumericCharacters
{
get { throw new Exception("The method or operation is not implemented."); }
}


public override int PasswordAttemptWindow
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override MembershipPasswordFormat PasswordFormat
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override string PasswordStrengthRegularExpression
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override bool RequiresUniqueEmail
{
get { throw new Exception("The method or operation is not implemented."); }
}

public override string ResetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}

public override bool UnlockUser(string userName)
{
throw new Exception("The method or operation is not implemented.");
}

public override void UpdateUser(MembershipUser user)
{
throw new Exception("The method or operation is not implemented.");
}

搜索更多相关主题的帖子: membership 数据库 定义 public private 
2006-10-02 21:21
luzihui
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-11
收藏
得分:0 

是添加不了数据了。会不会是这一点有问题?
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connStr);
try
{
conn.Open();
string sql = "insert into Membership(username,password,Email,passwordQuestion,passwordAnswer) values(@username,@password,@Email,@passwordQuestion,@passwordAnswer)";
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(sql, conn);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
command.Parameters.AddWithValue("@Email", email);
command.Parameters.AddWithValue("@passwordQuestion", passwordQuestion);
command.Parameters.AddWithValue("@passwordAnswer", passwordAnswer);
command.ExecuteNonQuery();
MembershipUser user = new MembershipUser("AccessMembershipProvider", username, providerUserKey, email, passwordQuestion, "", isApproved, true, DateTime.Now, DateTime.Now , DateTime.Now, DateTime.Now, DateTime.Now);
status = MembershipCreateStatus.Success;
return user;

}
catch
{
if (conn.State == ConnectionState.Open)
conn.Close();
status = MembershipCreateStatus.ProviderError;
return null;
}
}

public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new Exception("The method or operation is not implemented.");
}

2006-10-03 09:39
快速回复:[求助]关于使用自定义membership连接数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020091 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved