当前位置: 首页>>代码示例>>C#>>正文


C# NuoDbConnection.CreateCommand方法代码示例

本文整理汇总了C#中NuoDb.Data.Client.NuoDbConnection.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# NuoDbConnection.CreateCommand方法的具体用法?C# NuoDbConnection.CreateCommand怎么用?C# NuoDbConnection.CreateCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NuoDb.Data.Client.NuoDbConnection的用法示例。


在下文中一共展示了NuoDbConnection.CreateCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBulkLoadPerformance

        public void TestBulkLoadPerformance()
        {
            using (NuoDbConnection cnn = new NuoDbConnection(connectionString))
            {
                cnn.Open();
                Utils.DropTable(cnn, "temp");

                DbCommand createCommand = new NuoDbCommand("create table temp (col1 integer, col2 integer)", cnn);
                int result = createCommand.ExecuteNonQuery();

                DbCommand cmm = cnn.CreateCommand();
                cmm.CommandText = "insert into temp(col1, col2) values(?, ?)";
                cmm.Parameters.Add(new NuoDbParameter { DbType = DbType.Int32, ParameterName = "col1" });
                cmm.Parameters.Add(new NuoDbParameter { DbType = DbType.Int32, ParameterName = "col2" });
                cmm.Prepare();

                const int ROW_NUMBER = 40000;
                DateTime start = DateTime.Now;
                for (var i = 1; i <= ROW_NUMBER; i++)
                {
                    cmm.Parameters["col1"].Value = i;
                    cmm.Parameters["col2"].Value = 2 * i;
                    cmm.ExecuteNonQuery();
                }
                DateTime end = DateTime.Now;
                double insertTime = (end - start).TotalMilliseconds;

                Utils.DropTable(cnn, "temp2");
                createCommand = new NuoDbCommand("create table temp2 (col1 integer, col2 integer)", cnn);
                createCommand.ExecuteNonQuery();

                NuoDbBulkLoader loader = new NuoDbBulkLoader(connectionString);
                loader.DestinationTableName = "TEMP2";

                DbCommand command = new NuoDbCommand("select * from temp", cnn);
                DbDataReader reader = command.ExecuteReader();

                loader.BatchProcessed += new BatchProcessedEventHandler(loader_BatchProcessed);
                start = DateTime.Now;
                loader.WriteToServer(reader);
                end = DateTime.Now;

                double loadTime = (end - start).TotalMilliseconds;

                reader.Close();

                Console.WriteLine("{0} insert = {1}\n{0} bulk load = {2}\n", ROW_NUMBER, insertTime, loadTime);

                Assert.IsTrue(loadTime < insertTime, "BulkLoad takes more time than manual insertion");
            }
        }
开发者ID:biegomar,项目名称:nuodb-dotnet,代码行数:51,代码来源:TestFixture.cs

示例2: TestAsynchronousScalar1

        public void TestAsynchronousScalar1()
        {
            using (NuoDbConnection connection = new NuoDbConnection(connectionString))
            {
                NuoDbCommand countCommand = (NuoDbCommand)connection.CreateCommand();
                countCommand.CommandText = "select count(*) from hockey";

                connection.Open();

                IAsyncResult result = countCommand.BeginExecuteScalar();

                int count = (int)countCommand.EndExecuteScalar(result);
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:14,代码来源:TestFixture.cs

示例3: ResetPassword

        //
        // MembershipProvider.ResetPassword
        //
        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordReset)
            {
                throw new NotSupportedException("Password reset is not enabled.");
            }

            if (answer == null && RequiresQuestionAndAnswer)
            {
                UpdateFailureCount(username, "passwordAnswer");

                throw new ProviderException("Password answer required for password reset.");
            }

            string newPassword =
              System.Web.Security.Membership.GeneratePassword(newPasswordLength, MinRequiredNonAlphanumericCharacters);

            ValidatePasswordEventArgs args =
              new ValidatePasswordEventArgs(username, newPassword, true);

            OnValidatingPassword(args);

            if (args.Cancel)
                if (args.FailureInformation != null)
                    throw args.FailureInformation;
                else
                    throw new MembershipPasswordException("Reset password canceled due to password validation failure.");

            EnsureTableIsCreated();
            NuoDbConnection conn = null;
            int rowsAffected = 0;
            string passwordAnswer = "";
            DbDataReader reader = null;

            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT PasswordAnswer, IsLockedOut " +
                                      "FROM Users " +
                                      "WHERE Username = ? AND ApplicationName = ?";

                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = username;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

                    if (reader.Read())
                    {
                        if (reader.GetBoolean(1))
                            throw new MembershipPasswordException("The supplied user is locked out.");

                        passwordAnswer = reader.GetString(0);
                    }
                    else
                    {
                        throw new MembershipPasswordException("The supplied user name is not found.");
                    }

                    if (RequiresQuestionAndAnswer && !CheckPassword(answer, passwordAnswer))
                    {
                        UpdateFailureCount(username, "passwordAnswer");

                        throw new MembershipPasswordException("Incorrect password answer.");
                    }

                    using (DbCommand updateCmd = conn.CreateCommand())
                    {
                        updateCmd.CommandText = "UPDATE Users " +
                                                "SET Password = ?, LastPasswordChangedDate = ? " +
                                                "WHERE Username = ? AND ApplicationName = ? AND IsLockedOut = False";

                        IDbDataParameter passwordParameter = updateCmd.CreateParameter();
                        passwordParameter.Value = EncodePassword(newPassword);
                        passwordParameter.DbType = DbType.String;
                        updateCmd.Parameters.Add(passwordParameter);

                        IDbDataParameter lastPasswordChangedDateParameter = updateCmd.CreateParameter();
                        lastPasswordChangedDateParameter.Value = DateTime.Now;
                        lastPasswordChangedDateParameter.DbType = DbType.DateTime;
                        updateCmd.Parameters.Add(lastPasswordChangedDateParameter);

                        updateCmd.Parameters.Add(usernameParameter);

                        updateCmd.Parameters.Add(applicationNameParameter);

                        rowsAffected = updateCmd.ExecuteNonQuery();
                    }
//.........这里部分代码省略.........
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:101,代码来源:NuoDbMembershipProvider.cs

示例4: TestUpdateWithGeneratedKeys

        public void TestUpdateWithGeneratedKeys()
        {
            using (NuoDbConnection connection = new NuoDbConnection(connectionString))
            {
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                DbCommand updateCommand = connection.CreateCommand();
                updateCommand.CommandText = "update hockey set number = 99 where team = 'Bruins'";

                DbDataReader reader = updateCommand.ExecuteReader();
                Assert.IsNotNull(reader, "The command should return a generated keys recordset");
                Assert.IsFalse(reader.Read(), "The generated keys recordset should be empty");

                transaction.Rollback();
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:17,代码来源:TestFixture.cs

示例5: TestScalability

        public void TestScalability()
        {
            using (NuoDbConnection cnn = new NuoDbConnection(connectionString))
            {
                cnn.Open();
                Utils.DropTable(cnn, "temp");

                DbCommand createCommand = new NuoDbCommand("create table temp (col1 integer, col2 integer)", cnn);
                int result = createCommand.ExecuteNonQuery();

                DbCommand cmm = cnn.CreateCommand();
                cmm.CommandText = "insert into temp(col1, col2) values(?, ?)";
                cmm.Parameters.Add(new NuoDbParameter { DbType = DbType.Int32, ParameterName = "col1" });
                cmm.Parameters.Add(new NuoDbParameter { DbType = DbType.Int32, ParameterName = "col2" });
                cmm.Prepare();

                int[] count = new int[] { 1000, 5000, 10000, 20000, 40000 };
                double[] times = new double[count.Length];
                for (var k = 0; k < count.Length; k++)
                {
                    DateTime start = DateTime.Now;
                    for (var i = 1; i <= count[k]; i++)
                    {
                        cmm.Parameters["col1"].Value = i;
                        cmm.Parameters["col2"].Value = 2 * i;
                        cmm.ExecuteNonQuery();
                    }
                    DateTime end = DateTime.Now;
                    times[k] = (end - start).TotalMilliseconds;
                    if (k == 0)
                        Console.WriteLine("{0} runs = {1} msec", count[k], times[k]);
                    else
                    {
                        double countRatio = (count[k] / count[0]);
                        double timeRatio = (times[k] / times[0]);
                        Console.WriteLine("{0} runs = {1} msec => {2} {3}", count[k], times[k], countRatio, timeRatio);
                        Assert.IsTrue(timeRatio < (countRatio * 1.50), "Scalability at {2} rows is not linear! (time for {0} rows = {1}; time for {2} rows = {3} => ratio = {4} is greater than {5}",
                            new object[] { count[0], times[0], count[k], times[k], timeRatio, countRatio });

                    }
                }
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:43,代码来源:TestFixture.cs

示例6: TestAsynchronousUpdate2

        public void TestAsynchronousUpdate2()
        {
            NuoDbConnection connection = new NuoDbConnection(connectionString);
            connection.Open();
            Utils.DropTable(connection, "temp");

            NuoDbCommand countCommand = (NuoDbCommand)connection.CreateCommand();
            countCommand.CommandText = "create table temp (col string)";

            AsyncCallback callback = new AsyncCallback(HandleCallback3);
            IAsyncResult result = countCommand.BeginExecuteNonQuery(callback, countCommand);
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:12,代码来源:TestFixture.cs

示例7: TestPrepareDDLNoParameter

        public void TestPrepareDDLNoParameter()
        {
            using (NuoDbConnection connection = new NuoDbConnection(connectionString))
            {
                DbCommand command = connection.CreateCommand();
                connection.Open();

                command.CommandText = "create table xyz (col int)";
                command.Prepare();

                try
                {
                    int value = command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Assert.Fail("Executing a prepared DDL that doesn't use parameters reports an error: {0}", e.Message);
                }
                finally
                {
                    Utils.DropTable(connection, "xyz");
                }
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:24,代码来源:TestFixture.cs

示例8: TestNamedParameters3

        public void TestNamedParameters3()
        {
            using (NuoDbConnection connection = new NuoDbConnection(connectionString))
            {
                DbCommand command = connection.CreateCommand();
                connection.Open();

                command.CommandText = "select name as \"'?\" from \"hockey\" where name='? ?.fake' or number = ?.number and team = ?.team";
                NuoDbParameter p1 = new NuoDbParameter();
                p1.ParameterName = "TEAM";
                p1.Value = "Bruins";
                command.Parameters.Add(p1);
                NuoDbParameter p2 = new NuoDbParameter();
                p2.ParameterName = "NUMBER";
                p2.Value = 1;
                command.Parameters.Add(p2);
                command.Prepare();

                DbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine("\t{0}", reader["'?"]);
                }
                reader.Close();
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:26,代码来源:TestFixture.cs

示例9: ChangePasswordQuestionAndAnswer

        //
        // MembershipProvider.ChangePasswordQuestionAndAnswer
        //
        public override bool ChangePasswordQuestionAndAnswer(string username,
                      string password,
                      string newPwdQuestion,
                      string newPwdAnswer)
        {
            if (!ValidateUser(username, password))
                return false;

            int rowsAffected = 0;
            EnsureTableIsCreated();
            NuoDbConnection conn = null;
            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "UPDATE Users " +
                                      "SET PasswordQuestion = ?, PasswordAnswer = ? " +
                                      "WHERE Username = ? AND ApplicationName = ?";
                    IDbDataParameter questionParameter = cmd.CreateParameter();
                    questionParameter.Value = newPwdQuestion;
                    questionParameter.DbType = DbType.String;
                    cmd.Parameters.Add(questionParameter);
                    IDbDataParameter passwordParameter = cmd.CreateParameter();
                    passwordParameter.Value = EncodePassword(newPwdAnswer);
                    passwordParameter.DbType = DbType.String;
                    cmd.Parameters.Add(passwordParameter);
                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = username;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }
            catch (NuoDbSqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ChangePasswordQuestionAndAnswer");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                conn.Close();
            }

            if (rowsAffected > 0)
            {
                return true;
            }

            return false;
        }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:69,代码来源:NuoDbMembershipProvider.cs

示例10: UpdateFailureCount

        //
        // UpdateFailureCount
        //   A helper method that performs the checks and updates associated with
        // password failure tracking.
        //
        private void UpdateFailureCount(string username, string failureType)
        {
            EnsureTableIsCreated();
            NuoDbConnection conn = null;
            DbDataReader reader = null;
            DateTime windowStart = new DateTime();
            int failureCount = 0;

            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT FailedPasswordAttemptCount, " +
                                      "       FailedPasswordAttemptWindowStart, " +
                                      "       FailedPasswordAnswerAttemptCount, " +
                                      "       FailedPasswordAnswerAttemptWindowStart " +
                                      "FROM Users " +
                                      "WHERE Username = ? AND ApplicationName = ?";

                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = username;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

                    if (reader.HasRows)
                    {
                        reader.Read();

                        if (failureType == "password")
                        {
                            failureCount = reader.GetInt32(0);
                            windowStart = reader.GetDateTime(1);
                        }

                        if (failureType == "passwordAnswer")
                        {
                            failureCount = reader.GetInt32(2);
                            windowStart = reader.GetDateTime(3);
                        }
                    }

                    reader.Close();

                    DateTime windowEnd = windowStart.AddMinutes(PasswordAttemptWindow);

                    if (failureCount == 0 || DateTime.Now > windowEnd)
                    {
                        // First password failure or outside of PasswordAttemptWindow.
                        // Start a new password failure count from 1 and a new window starting now.

                        using (DbCommand updateCmd = conn.CreateCommand())
                        {
                            if (failureType == "password")
                                updateCmd.CommandText = "UPDATE Users " +
                                                        "SET FailedPasswordAttemptCount = ?, " +
                                                        "    FailedPasswordAttemptWindowStart = ? " +
                                                        "WHERE Username = ? AND ApplicationName = ?";

                            if (failureType == "passwordAnswer")
                                updateCmd.CommandText = "UPDATE Users " +
                                                        "SET FailedPasswordAnswerAttemptCount = ?, " +
                                                        "    FailedPasswordAnswerAttemptWindowStart = ? " +
                                                        "WHERE Username = ? AND ApplicationName = ?";

                            updateCmd.Parameters.Clear();

                            IDbDataParameter countParameter = updateCmd.CreateParameter();
                            countParameter.Value = 1;
                            countParameter.DbType = DbType.Int32;
                            updateCmd.Parameters.Add(countParameter);
                            IDbDataParameter windowStartParameter = updateCmd.CreateParameter();
                            windowStartParameter.Value = DateTime.Now;
                            windowStartParameter.DbType = DbType.DateTime;
                            updateCmd.Parameters.Add(windowStartParameter);
                            IDbDataParameter updateUsernameParameter = updateCmd.CreateParameter();
                            updateUsernameParameter.Value = username;
                            updateUsernameParameter.DbType = DbType.String;
                            updateCmd.Parameters.Add(updateUsernameParameter);

                            updateCmd.Parameters.Add(applicationNameParameter);

                            if (cmd.ExecuteNonQuery() < 0)
                                throw new ProviderException("Unable to update failure count and window start.");
                        }
                    }
                    else
//.........这里部分代码省略.........
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:101,代码来源:NuoDbMembershipProvider.cs

示例11: EnsureTableIsCreated

        //
        // EnsureTableIsCreated
        //   A helper function that creates the table if it is not yet present
        //
        private void EnsureTableIsCreated()
        {
            NuoDbConnection conn = null;

            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "CREATE TABLE IF NOT EXISTS Users " +
                                      " (PKID String NOT NULL PRIMARY KEY, "+
                                      "  Username Text (255) NOT NULL, " +
                                      "  ApplicationName Text (255) NOT NULL, " +
                                      "  Email Text (128) NOT NULL, " +
                                      "  Comment Text (255), " +
                                      "  Password Text (128) NOT NULL, " +
                                      "  PasswordQuestion Text (255), " +
                                      "  PasswordAnswer Text (255), " +
                                      "  IsApproved Boolean, " +
                                      "  LastActivityDate DateTime, " +
                                      "  LastLoginDate DateTime, " +
                                      "  LastPasswordChangedDate DateTime, " +
                                      "  CreationDate DateTime, " +
                                      "  IsOnLine Boolean, " +
                                      "  IsLockedOut Boolean, " +
                                      "  LastLockedOutDate DateTime, " +
                                      "  FailedPasswordAttemptCount Integer, " +
                                      "  FailedPasswordAttemptWindowStart DateTime, " +
                                      "  FailedPasswordAnswerAttemptCount Integer, " +
                                      "  FailedPasswordAnswerAttemptWindowStart DateTime " +
                                      ")";
                    cmd.ExecuteNonQuery();
                }
            }
            catch (NuoDbSqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "EnsureTableIsCreated");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                conn.Close();
            }
        }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:58,代码来源:NuoDbMembershipProvider.cs

示例12: ValidateUser

        //
        // MembershipProvider.ValidateUser
        //
        public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;

            EnsureTableIsCreated();
            NuoDbConnection conn = null;
            DbDataReader reader = null;
            bool isApproved = false;
            string pwd = "";

            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT Password, IsApproved " +
                                      "FROM Users " +
                                      "WHERE Username = ? AND ApplicationName = ? AND IsLockedOut = False";

                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = username;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

                    if (reader.Read())
                    {
                        pwd = reader.GetString(0);
                        isApproved = reader.GetBoolean(1);
                    }
                    else
                    {
                        return false;
                    }

                    reader.Close();

                    if (CheckPassword(password, pwd))
                    {
                        if (isApproved)
                        {
                            isValid = true;

                            using (DbCommand updateCmd = conn.CreateCommand())
                            {
                                updateCmd.CommandText = "UPDATE Users " +
                                                        "SET LastLoginDate = ? " +
                                                        "WHERE Username = ? AND ApplicationName = ?";

                                IDbDataParameter lastLoginDateParameter = updateCmd.CreateParameter();
                                lastLoginDateParameter.Value = DateTime.Now;
                                lastLoginDateParameter.DbType = DbType.DateTime;
                                updateCmd.Parameters.Add(lastLoginDateParameter);

                                updateCmd.Parameters.Add(usernameParameter);

                                updateCmd.Parameters.Add(applicationNameParameter);

                                updateCmd.ExecuteNonQuery();
                            }
                        }
                        else
                        {
                            conn.Close();

                            UpdateFailureCount(username, "password");
                        }
                    }
                }
            }
            catch (NuoDbSqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ValidateUser");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                if (reader != null) { reader.Close(); }
                conn.Close();
            }

            return isValid;
//.........这里部分代码省略.........
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:101,代码来源:NuoDbMembershipProvider.cs

示例13: UpdateUser

        //
        // MembershipProvider.UpdateUser
        //
        public override void UpdateUser(MembershipUser user)
        {
            EnsureTableIsCreated();
            NuoDbConnection conn = null;

            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "UPDATE Users " +
                                      "SET Email = ?, Comment = ?, IsApproved = ? " +
                                      "WHERE Username = ? AND ApplicationName = ?";

                    IDbDataParameter emailParameter = cmd.CreateParameter();
                    emailParameter.Value = user.Email;
                    emailParameter.DbType = DbType.String;
                    cmd.Parameters.Add(emailParameter);
                    IDbDataParameter commentParameter = cmd.CreateParameter();
                    commentParameter.Value = user.Comment;
                    commentParameter.DbType = DbType.String;
                    cmd.Parameters.Add(commentParameter);
                    IDbDataParameter isApprovedParameter = cmd.CreateParameter();
                    isApprovedParameter.Value = user.IsApproved;
                    isApprovedParameter.DbType = DbType.Boolean;
                    cmd.Parameters.Add(isApprovedParameter);
                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = user.UserName;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    cmd.ExecuteNonQuery();
                }
            }
            catch (NuoDbSqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "UpdateUser");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                conn.Close();
            }
        }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:61,代码来源:NuoDbMembershipProvider.cs

示例14: ChangePassword

        //
        // System.Web.Security.MembershipProvider methods.
        //
        //
        // MembershipProvider.ChangePassword
        //
        public override bool ChangePassword(string username, string oldPwd, string newPwd)
        {
            if (!ValidateUser(username, oldPwd))
                return false;

            ValidatePasswordEventArgs args =
              new ValidatePasswordEventArgs(username, newPwd, true);

            OnValidatingPassword(args);

            if (args.Cancel)
                if (args.FailureInformation != null)
                    throw args.FailureInformation;
                else
                    throw new MembershipPasswordException("Change password canceled due to new password validation failure.");

            int rowsAffected = 0;

            EnsureTableIsCreated();
            NuoDbConnection conn = null;
            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "UPDATE Users " +
                                      "SET Password = ?, LastPasswordChangedDate = ? " +
                                      "WHERE Username = ? AND ApplicationName = ?";
                    IDbDataParameter passwordParameter = cmd.CreateParameter();
                    passwordParameter.Value = EncodePassword(newPwd);
                    passwordParameter.DbType = DbType.String;
                    cmd.Parameters.Add(passwordParameter);
                    IDbDataParameter lastPasswordChangedDataParameter = cmd.CreateParameter();
                    lastPasswordChangedDataParameter.Value = DateTime.Now;
                    lastPasswordChangedDataParameter.DbType = DbType.DateTime;
                    cmd.Parameters.Add(lastPasswordChangedDataParameter);
                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = username;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }
            catch (NuoDbSqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ChangePassword");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                conn.Close();
            }

            if (rowsAffected > 0)
            {
                return true;
            }

            return false;
        }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:81,代码来源:NuoDbMembershipProvider.cs

示例15: UnlockUser

        //
        // MembershipProvider.UnlockUser
        //
        public override bool UnlockUser(string username)
        {
            EnsureTableIsCreated();
            NuoDbConnection conn = null;
            int rowsAffected = 0;
            try
            {
                conn = new NuoDbConnection(connectionString);
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "UPDATE Users " +
                                      "SET IsLockedOut = False, LastLockedOutDate = ? " +
                                      "WHERE Username = ? AND ApplicationName = ?";

                    IDbDataParameter lastLockedOutDateParameter = cmd.CreateParameter();
                    lastLockedOutDateParameter.Value = DateTime.Now;
                    lastLockedOutDateParameter.DbType = DbType.DateTime;
                    cmd.Parameters.Add(lastLockedOutDateParameter);
                    IDbDataParameter usernameParameter = cmd.CreateParameter();
                    usernameParameter.Value = username;
                    usernameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(usernameParameter);
                    IDbDataParameter applicationNameParameter = cmd.CreateParameter();
                    applicationNameParameter.Value = pApplicationName;
                    applicationNameParameter.DbType = DbType.String;
                    cmd.Parameters.Add(applicationNameParameter);

                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }
            catch (NuoDbSqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "UnlockUser");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                conn.Close();
            }

            if (rowsAffected > 0)
                return true;

            return false;
        }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:58,代码来源:NuoDbMembershipProvider.cs


注:本文中的NuoDb.Data.Client.NuoDbConnection.CreateCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。