Rexiology::Work

Microsoft, Information Technologies...

Community

News

  • From Taiwan, living and working at Tokyo, Japan.




Recent Posts

Tags

Microsoft Sites

Other Sites

Blog pools

Bloggers

Archives

Site Info



Locations of visitors to this page




Logos & Chicklets


GeoURL


Rex's Certifications
Rex's Certifications


Creative Commons授權條款
本 著作 係採用
Creative Commons 授權條款



January 2008 - Posts

.NET Framework Source Code now Available...

crosspost from http://blogs.msdn.com/rextang

[via ScottGu]

Available source code for now:

  • NET Base Class Libraries (including System, System.CodeDom, System.Collections, System.ComponentModel, System.Diagnostics, System.Drawing, System.Globalization, System.IO, System.Net, System.Reflection, System.Runtime, System.Security, System.Text, System.Threading, etc).
  • ASP.NET (System.Web, System.Web.Extensions)
  • Windows Forms (System.Windows.Forms)
  • Windows Presentation Foundation (System.Windows)
  • ADO.NET and XML (System.Data and System.Xml)
Enabling Reference Source Access in Visual Studio 2008

Enabling .NET Framework source access within Visual Studio 2008 only takes a few minutes to setup. Shawn Burke has a detailed blog post that covers the exact steps on how to enable this in more depth here.

If you run into problems or have questions setting it up, please post a question in the Reference Source Forum on MSDN here.

Reference License

The .NET Framework source is being released under a read-only reference license. When we announced that we were releasing the source back in October, some people had concerns about the potential impact of their viewing the source. To help clarify and address these concerns, we made a small change to the license to specifically call out that the license does not apply to users developing software for a non-Windows platform that has “the same or substantially the same features or functionality” as the .NET Framework. If the software you are developing is for Windows platforms, you can look at the code, even if that software has "the same or substantially the same features or functionality" as the .NET Framework.

FYI.

asp.net: checking session size in SQL Server ASPState DB...

crosspost from http://blogs.msdn.com/rextang

by setting asp.net application to save session state into SQL Server database, not only can scale application out with multiple web servers, but also provided a way to investigate session usage.

Saving session state in SQL Server database will be slower than InProc session state, since it requires Serialization / DeSerialization of session data and there will be round trips between web server and database server, therefore, session size / usage in asp.net application becomes an important factor of optimizing and scaling out an application.

To create a session state database for using in asp.net application, refer to aspnet_reqsql.exe usage, using the command

aspnet_reqsql.exe -ssadd -sstype p -E

using -E if you are authenticating using windows credential (trusted connection), or using -U and -P to input sql server login and password. the default session state database name is "ASPState"

Inside ASPState db, there are 2 tables: "ASPStateTempApplications" and "ASPStateTempSessions". ASPStateTempApplications table have the mapping of self-made application-id and infomation of web virtual directory. the application-id is a decimal int value.

ASPStateTempSessions table is the place where the actualy session data is stored. the key field is SessionId, which is a 32 bytes string combined with asp.net session-id (the first 24 bytes) and application-id (the last 8 bytes). the application-id in SessionId field is represented in hex value, which is different than the id in ASPStateTempApplications table, which is in decimal value. thus the conversion become necessary if trying to mapping those 2 tables to create meaningful report in one query.

I just wrote a post with the function to convert HexString to VarBinary and to convert VarBinary to Int, so the conversion should be no problem if using that self-defined function. now here is the query for getting session size and mapping each session to its virtual directory:

select
    SessionId,
    substring(SessionId,25,8) as AppIDHex,
    convert(int, dbo.HexStrToVarBinary(substring(SessionId,25,8))) as AppIDDec,
    b.AppName,
    datalength(SessionItemLong) as SessionSize
from dbo.ASPStateTempSessions as a
    left outer join dbo.ASPStateTempApplications as b on
   convert(int, dbo.HexStrToVarBinary(substring(a.SessionId,25,8))) = b.AppId

where datalength(SessionItemLong) > 0
order by SessionSize desc

Before running this query, be sure to first add the "HexStrToVarBinary" function to ASPState database, which stated in my last post.

[UPDATE 2008/01/13 07:50 Start]

since the AppId in ASPStateTempApplications might contain minus decimal values, the conversion from hex to decimal will have chances not match the decimal values of AppId.

to solve this, not converting to decimal value for the mapping, but using hex value for matching 2 tables:

SELECT
    a.SessionId,
    SUBSTRING(a.SessionId, 25, 8) AS AppIDHex,
    b.AppId AS AppIDDec,
    b.AppName,
    DATALENGTH(a.SessionItemLong) AS SessionSize
FROM
    dbo.ASPStateTempSessions AS a
    LEFT OUTER JOIN
    dbo.ASPStateTempApplications AS b
    ON
    SUBSTRING(a.SessionId, 25, 8) =
    SUBSTRING(sys.fn_varbintohexstr(CONVERT(VarBinary,b.AppId)), 3, 8)
WHERE
    (DATALENGTH(a.SessionItemLong) > 0)
ORDER BY SessionSize DESC

by using this query there is no necessary to use self-made function to convert hex string to varbinary value, but have to use the built-in sql function "sys.fn_varbintohexstr". this query guarantees the match of those 2 tables.

[UPDATE 2008/01/13 07:50 End]

the query result is like the following:

now you can see each session state with its size and where the virtual directory the session is belong to, to get an idea of where the problem is at...

by seeing the above result, I got a session with size around 18mb, which is not a good idea... imaging each page request of this session, the 18mb data transfer between sql server and web server, and serialize / deserialize of a 18mb data... well, I'll write further posts if I got it solved... 

T-SQL: Convert Hex String to VarBinary...

crosspost from http://blogs.msdn.com/rextang

Here is some conversion functions in SQL Server...

To convert between int and hex values, by referring to this post:

SELECT 'Int -> Hex'
SELECT CONVERT(VARBINARY(8), 16777215)
SELECT 'Hex -> Int'
SELECT CONVERT(INT, 0xFFFFFF)

To convert a VarBinary to a HexString, by referring to Peter DeBetta's post, there is a function in SQL Server 2005 with the name "sys.fn_varbintohexstr" to do the job.

To convert a HexString to a VarBinary, there is no built-in function to do so. Peter DeBetta wrote a function to do this in above post link, and later at Michael.Net's blog post, there is an improved function to do the job. I'll also document here for my reference.

CREATE FUNCTION dbo.HexStrToVarBinary(@hexstr varchar(8000))
RETURNS varbinary(8000)
AS
BEGIN
DECLARE @hex char(1), @i int, @place bigint, @a bigint
SET @i = LEN(@hexstr)

set @place = convert(bigint,1)
SET @a = convert(bigint, 0)

WHILE (@i > 0 AND (substring(@hexstr, @i, 1) like '[0-9A-Fa-f]'))
BEGIN
SET @hex = SUBSTRING(@hexstr, @i, 1)
SET @a = @a +
convert(bigint, CASE WHEN @hex LIKE '[0-9]'
THEN CAST(@hex as int)
ELSE CAST(ASCII(UPPER(@hex))-55 as int) end * @place)
set @place = @place * convert(bigint,16)
SET @i = @i - 1

END

RETURN convert(varbinary(8000),@a)
END
GO

I'll use those functions in my next post to check the session size in asp.net applications...