SQL aspnet_profile

2024-02-24

知道如何使用 SQL 从基于 UserID 的 aspnet_profile 表中获取用户名字和姓氏,因为我想在 Telerik Reporting 中使用作为用户参数。

示例行(名字是 George,姓氏是 Test):

UserID: 06b24b5c-9aa1-426e-b7e4-0771c5f85e85

PropertyName: MobilePhone:S:0:0:Initials:S:0:1:City:S:1:14:FirstName:S:15:6:PostalCode:S:21:7:‌​WorkPhone:S:28:12:LastName:S:40:5:Address1:S:45:17:Address2:S:62:0:Province:S:62:‌​2:Organization:S:64:4:ClinicId:S:68:1:Country:S:69:6:Fax:S:75:0:MSPNumber:S:75:0:‌​ 

PropertyValuesString: HEast HustonEASGeorgeT7D 1N8604-111-2222Test5555 Beddtvue AveDCHCNL2Canada

PropertyValuesBinary: <Binary data>

LastUpdateDate: 2010-01-02 22:22:03.947

如果你坚持使用 SQL,我确信大量子串 http://msdn.microsoft.com/en-us/library/ms187748.aspxs and PATINDEX http://msdn.microsoft.com/en-us/library/ms188395.aspxes 会带你到达那里,但它不会是一个干净的解决方案。

Update: 用户373721 https://stackoverflow.com/users/373721/user373721找到了一个很棒的资源并发布了关于它的评论,但它很容易被错过,所以我决定也将其添加到答案中 -如何使用 T-SQL 从 MS SQL 数据库获取 asp.net 配置文件值? http://www.karpach.com/Get-asp-net-profile-value-MS-SQL-database-using-T-SQL.htm

内置的dbo.aspnet_Profile_GetProperties存储过程 https://techwriter.me/samples/database/aspnetdb/aspnetdb.html#PR-ASPNETDB-aspnet_Profile_GetProperties返回PropertyValuesString稍后在中解析的值ParseDataFromDB功能。

private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
{
    if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
    {
        EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_BEGIN, HttpContext.Current.WorkerRequest);
    }
    HttpContext current = HttpContext.Current;
    string[] names = null;
    string values = null;
    byte[] buffer = null;
    if (current != null)
    {
        if (!current.Request.IsAuthenticated)
        {
            string anonymousID = current.Request.AnonymousID;
        }
        else
        {
            string name = current.User.Identity.Name;
        }
    }
    try
    {
        SqlConnectionHolder connection = null;
        SqlDataReader reader = null;
        try
        {
            connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
            this.CheckSchemaVersion(connection.Connection);
            SqlCommand command = new SqlCommand("dbo.aspnet_Profile_GetProperties", connection.Connection) {
                CommandTimeout = this.CommandTimeout,
                CommandType = CommandType.StoredProcedure
            };
            command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName));
            command.Parameters.Add(this.CreateInputParam("@UserName", SqlDbType.NVarChar, userName));
            command.Parameters.Add(this.CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
            reader = command.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                names = reader.GetString(0).Split(new char[] { ':' });
                values = reader.GetString(1);
                int length = (int) reader.GetBytes(2, 0L, null, 0, 0);
                buffer = new byte[length];
                reader.GetBytes(2, 0L, buffer, 0, length);
            }
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
                connection = null;
            }
            if (reader != null)
            {
                reader.Close();
            }
        }
        ProfileModule.ParseDataFromDB(names, values, buffer, svc);
        if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
        {
            EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_END, HttpContext.Current.WorkerRequest, userName);
        }
    }
    catch
    {
        throw;
    }
}

 

internal static void ParseDataFromDB(string[] names, string values, byte[] buf, SettingsPropertyValueCollection properties)
{
    if (((names != null) && (values != null)) && ((buf != null) && (properties != null)))
    {
        try
        {
            for (int i = 0; i < (names.Length / 4); i++)
            {
                string str = names[i * 4];
                SettingsPropertyValue value2 = properties[str];
                if (value2 != null)
                {
                    int startIndex = int.Parse(names[(i * 4) + 2], CultureInfo.InvariantCulture);
                    int length = int.Parse(names[(i * 4) + 3], CultureInfo.InvariantCulture);
                    if ((length == -1) && !value2.Property.PropertyType.IsValueType)
                    {
                        value2.PropertyValue = null;
                        value2.IsDirty = false;
                        value2.Deserialized = true;
                    }
                    if (((names[(i * 4) + 1] == "S") && (startIndex >= 0)) && ((length > 0) && (values.Length >= (startIndex + length))))
                    {
                        value2.SerializedValue = values.Substring(startIndex, length);
                    }
                    if (((names[(i * 4) + 1] == "B") && (startIndex >= 0)) && ((length > 0) && (buf.Length >= (startIndex + length))))
                    {
                        byte[] dst = new byte[length];
                        Buffer.BlockCopy(buf, startIndex, dst, 0, length);
                        value2.SerializedValue = dst;
                    }
                }
            }
        }
        catch
        {
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SQL aspnet_profile 的相关文章

  • 限制分页页数

    objConnect mysql connect localhost root or die mysql error objDB mysql select db Test strSQL SELECT FROM UserAddedRecord
  • SQL中如何识别字符串的第一个字符是数字还是字符

    我需要将数据中的第一个字符识别为 SQL Server 中的数字或字符 我对此比较陌生 我不知道从哪里开始 但这是我到目前为止所做的事情 我的数据看起来像这样 TypeDep Transfer From 4Z2 Transfer From
  • 如何检查一个值是否已经存在以避免重复?

    我有一个 URL 表 但我不想要任何重复的 URL 如何使用 PHP MySQL 检查给定 URL 是否已在表中 如果您不想重复 可以执行以下操作 添加唯一性约束 use REPLACE http dev mysql com doc ref
  • 如何避免连接两个表时重复

    Student Table SID Name 1 A 2 B 3 C Marks Table id mark subject 1 50 physics 2 40 biology 1 50 chemistry 3 30 mathematics
  • Oracle SQL-根据记录的日期与历史记录标记记录

    这是我在论坛上的第一篇文章 通常我能够找到我需要的东西 但说实话 我不太确定如何针对该问题提出正确的问题 因此 如果论坛上已经有答案而我错过了 请接受我的歉意 我通过 Benthic Software 在 Oracle 数据库中运行以下代码
  • 根据最大值连接表

    这是我正在谈论的内容的一个简化示例 Table students exam results id name id student id score date 1 Jim 1 1 73 8 1 09 2 Joe 2 1 67 9 2 09 3
  • Google BigQuery,使用“unnest”函数时丢失了空行

    StandardSQL WITH tableA AS SELECT T001 T002 T003 AS T id 1 5 AS L id UNION ALL SELECT T008 T009 AS T id NULL AS L id SEL
  • SQL 分隔符上的逗号分隔列

    这是一个 split 函数 它可以应用为dbo Split sf we fs we 当我将字符串更改为列名时 它不起作用 例如dbo Split table columnName Select from dbo Split email pr
  • Android 中读取未提交的事务

    我正在进行大量数据库操作 这会向我的数据库添加大约 10 000 条记录 由于这可能需要很长时间 因此最好使用事务 db startTransaction do write operations db setTransactionSucce
  • 从java运行sqlplus脚本的简单方法

    我有包含 sqlplus 特定脚本的 sql 文件 它包括 或 作为语句终止符 执行存储过程的 EXEC 等 我需要从 java jdbc 执行此脚本 而不需要 sqlplus sql ant任务 maven sql插件无法处理不同的终止符
  • 无法访问 Big Query 中类型为 ARRAY> 的字段

    我正在尝试在 BigQuery 上使用标准 SQL 方言 即不是旧版 SQL 运行查询 我的查询是 SELECT date hits referer FROM refresh ga sessions xxxxxx LIMIT 1000 但不
  • MySQL通过UPDATE/DELETE合并重复数据记录

    我有一个看起来像这样的表 mysql gt SELECT FROM Colors ID USERNAME RED GREEN YELLOW BLUE ORANGE PURPLE 1 joe 1 null 1 null null null 2
  • MySQL,连接两列

    MySQL 表中有两列 SUBJECT and YEAR 我想生成一个字母数字唯一编号 其中包含主题和年份的串联数据 我怎样才能做到这一点 是否可以使用像这样的简单运算符 您可以使用CONCAT http dev mysql com doc
  • PL/SQL 过程:如何返回 select 语句?

    我想创建一个存储过程 on ORACLE数据库服务器我的问题是 我不知道如何返回 select 语句 这是程序中应包含的逻辑 输入参数 过滤器1 int 过滤器2 字符串 with cte as select val1 val2 stdde
  • 将自动递增值添加到只有一列的表中

    我需要创建一个基本上仅保留索引列表的表 因此 我创建了一个只有一个名为 id 的自动递增列的表 但是 我似乎无法隐式地将自动递增值添加到该表中 我知道通常当您在表中有这样一列 不仅仅是此列 时 您可以执行以下操作 插入表 col1 col2
  • 如何选择列值不不同的每一行

    我需要运行一个 select 语句 返回列值不不同的所有行 例如 EmailAddress 例如 如果表格如下所示 CustomerName EmailAddress Aaron email protected cdn cgi l emai
  • 从一张表更新并插入另一张表

    我有两张桌子 table1 ID 代码 姓名 table2 ID 代码 姓名 具有相同的列 我想将数据从 table1 插入到 table2 或更新列 如果 table2 中存在 table1 ID table2 ID 执行此操作的简单方法
  • 如何在 Postgresql 中将 GIST 或 GIN 索引与 hstore 列一起使用?

    我正在使用 postgresql 9 3 的 hstore 我正在尝试对 hstore 列使用索引就像文档所述 http www postgresql org docs 9 3 static hstore html 我的问题是索引似乎没有被
  • 索引在 NOT IN 或 <> 子句中起作用吗?

    我读过 至少 Oracle 数据库中的普通索引基本上是 B 树结构 因此存储处理适当根节点的记录 小于 根的记录被迭代地存储在树的左侧部分 而 大于 根的记录被存储在右侧部分 正是这种存储方法有助于通过树遍历实现更快的扫描 因为深度和广度都
  • 如何重置 SQL Server 中表的 IDENTITY 列? [复制]

    这个问题在这里已经有答案了 我怎样才能重置我的IDENTITY我已经填充的表中的列 我尝试过类似的方法 但它不起作用 WITH TBL AS SELECT ROW NUMBER OVER ORDER BY profile id AS RN

随机推荐