我弄的是连接到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.");
}