Monday, February 13, 2012
ASP.net newbie trying to build a forum
I'm an absolute newbie to asp.net... and recently got a start by visiting the beginner developer learning center at the msdn website. I have gone through all of the videos, and now I'm trying to build my first asp.net website... which would be an imaginary forum. I have the following tables in the database used in my application:
Categories
CategoryID int
CategoryName nvarchar(50)
CategoryDescription nvarchar(200)
Threads
ThreadID bigint(8)
CategoryID int
Subject nvarchar(50)
PostedDate datetime
PostedBy nvarchar(10)
Messages
MessageID bigint(8)
ThreadID bigint(8)
MessageBody nvarchar(200)
ReplyToID bigint(8)
User char(10)
You get the idea about what I'm trying to do.
Now, I have successfully written Categories.aspx, and Threads.aspx to display the sample data which I added. The problem is with the messages.aspx. I have no idea how to output data which would give me a means to sort and indent the messages according to the way the users would reply. I mean... users might reply to a message, and another might reply to the reply of that message... creating one big hierarchical mess. So I'm stuck... I can't build my imaginary forum.
Anyone experienced with writing code for forums with SQL server as the back end?
I am hoping to learn some new things about SQL server... maybe... XML? Which would solve my problem? I am already a little familiar with XML and XSL.
Many thanks in advance.
Mohamed Shafiee.
Hello Mohamed,
While this isn't an ASP.NET focused group, and while I don't believe SQLXML
is going to buy you anything here, here's an example that might get you started.
use scratch
go
-- make the message table
drop table dbo.messages
go
create table dbo.messages(
MessageID bigint primary key,
ThreadID bigint not null,
MessageBodynvarchar(200) not null,
ReplyToID bigint null foreign key references dbo.messages(messageID),
PostedBy varchar(50) not null default suser_sname())
go
set nocount on
go
-- some dummy messages
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (1,1,'1',null)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (2,1,'1-1',1)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (3,1,'1-2',1)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (4,1,'1-2-1',3)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (5,1,'1-2-2',3)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (6,1,'1-2-2-1',5)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (7,1,'1-2-2-2',5)
insert into dbo.messages(messageID,threadID,messageBody,ReplyT oID)
values (8,1,'1-2-1-1',4)
go
-- @.tid bigint is the ThreadID selected
-- @.rtm bigint is the Message user wants to reply to
drop procedure dbo.GetThreadForMessage
go
create procedure dbo.GetThreadForMessage(@.tid bigint, @.rtm bigint)
as begin
-- Get all the messages in this thread, "nested" by level
;with cte1 as (
select m1.messageID,m1.threadID,m1.MessageBody,m1.ReplyTo ID,m1.PostedBy,
cast(0 as int) as lvl
from dbo.messages m1
where m1.threadID = @.tid and m1.ReplyToID is null
union all
select mr.messageID,mr.threadID,mr.MessageBody,mr.ReplyTo ID,mr.PostedBy,
cte1.lvl + 1
from dbo.messages mr
join cte1 on mr.ReplyToID = cte1.MessageID
where mr.threadID = @.tid),
-- Get the reponses leading to the replying-to message.
cte2 as (
select replyToID from dbo.messages where messageID = @.rtm
union all
select m2.replyToID from dbo.messages m2
join cte2 on m2.messageID = cte2.replyToID
)
-- Last Message in thread
select * from cte1
where cte1.messageID = @.rtm
union all
-- Other messages in thread
select * from cte1
where cte1.messageID in (select ReplyToID from cte2)
union
-- Base message
select * from cte1 where cte1.replyToID is null
order by cte1.lvl desc
for xml path('message'),root('messages'),type
end
go
exec GetThreadForMessage 1,7
go
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
ASP.net newbie trying to build a forum
I'm an absolute newbie to asp.net... and recently got a start by visiting th
e beginner developer learning center at the msdn website. I have gone throug
h all of the videos, and now I'm trying to build my first asp.net website...
which would be an imaginary forum. I have the following tables in the datab
ase used in my application:
Categories
CategoryID int
CategoryName nvarchar(50)
CategoryDescription nvarchar(200)
Threads
ThreadID bigint(8)
CategoryID int
Subject nvarchar(50)
PostedDate datetime
PostedBy nvarchar(10)
Messages
MessageID bigint(8)
ThreadID bigint(8)
MessageBody nvarchar(200)
ReplyToID bigint(8)
User char(10)
You get the idea about what I'm trying to do.
Now, I have successfully written Categories.aspx, and Threads.aspx to displa
y the sample data which I added. The problem is with the messages.aspx. I ha
ve no idea how to output data which would give me a means to sort and indent
the messages according to the way the users would reply. I mean... users mi
ght reply to a message, and another might reply to the reply of that message
.. creating one big hierarchical mess. So I'm stuck... I can't build my ima
ginary forum.
Anyone experienced with writing code for forums with SQL server as the back
end?
I am hoping to learn some new things about SQL server... maybe... XML? Which
would solve my problem? I am already a little familiar with XML and XSL.
Many thanks in advance.
Mohamed Shafiee.Hello Mohamed,
While this isn't an ASP.NET focused group, and while I don't believe SQLXML
is going to buy you anything here, here's an example that might get you star
ted.
use scratch
go
-- make the message table
drop table dbo.messages
go
create table dbo.messages(
MessageID bigint primary key,
ThreadID bigint not null,
MessageBody nvarchar(200) not null,
ReplyToID bigint null foreign key references dbo.messages(messageID),
PostedBy varchar(50) not null default suser_sname())
go
set nocount on
go
-- some dummy messages
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (1,1,'1',null)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (2,1,'1-1',1)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (3,1,'1-2',1)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (4,1,'1-2-1',3)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (5,1,'1-2-2',3)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (6,1,'1-2-2-1',5)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (7,1,'1-2-2-2',5)
insert into dbo. messages(messageID,threadID,messageBody,
ReplyToID)
values (8,1,'1-2-1-1',4)
go
-- @.tid bigint is the ThreadID selected
-- @.rtm bigint is the Message user wants to reply to
drop procedure dbo.GetThreadForMessage
go
create procedure dbo.GetThreadForMessage(@.tid bigint, @.rtm bigint)
as begin
-- Get all the messages in this thread, "nested" by level
;with cte1 as (
select m1.messageID,m1.threadID,m1.MessageBody,m1.ReplyToID,m1.PostedBy,
cast(0 as int) as lvl
from dbo.messages m1
where m1.threadID = @.tid and m1.ReplyToID is null
union all
select mr.messageID,mr.threadID,mr.MessageBody,mr.ReplyToID,mr.PostedBy,
cte1.lvl + 1
from dbo.messages mr
join cte1 on mr.ReplyToID = cte1.MessageID
where mr.threadID = @.tid),
-- Get the reponses leading to the replying-to message.
cte2 as (
select replyToID from dbo.messages where messageID = @.rtm
union all
select m2.replyToID from dbo.messages m2
join cte2 on m2.messageID = cte2.replyToID
)
-- Last Message in thread
select * from cte1
where cte1.messageID = @.rtm
union all
-- Other messages in thread
select * from cte1
where cte1.messageID in (select ReplyToID from cte2)
union
-- Base message
select * from cte1 where cte1.replyToID is null
order by cte1.lvl desc
for xml path('message'),root('messages'),type
end
go
exec GetThreadForMessage 1,7
go
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
Thursday, February 9, 2012
ASP.NET & anti-virus & SSRS 2005
Below, I have pasted a portion of an MS MSDN article dealing with a specific issue we are having with Report Server performance. The URL (http://support.microsoft.com/kb/821438/en-us) is the MS KB article on the described fix. The fix mentioned is for "ASP.NET 1.1" but our BP Report Server is using "ASP.NET 2.0".
Has anyone encountered and resolved and how?
Running on box:
ASP.NET 2.0.50727;
SSRS 2005 Sp1 + Hotfix#2175;
Win Server 2003, R2, x64, SP1
Trend Micro OfficeScan Cleint for Win 2003/xp v7.3
IIS Version (I cannot find this #) - ? IE 6.0
===========================
Report Manager or the report server runs very slowly
In some circumstances, ASP.NET applications run very slowly on computers that are running anti-virus software. If the Report Server Web service is restarting frequently, and you are running anti-virus software, you can obtain an ASP.NET fix from Microsoft Customer Support Services.
Symptoms include Web applications or Application Domains restarting for no apparent reason, slow performance, session restarts, and more. For more information about the symptoms, cause, and resolution, see Microsoft Knowledge Base article 821438.
You can find out whether there are excessive server restarts by viewing the number of reportserver_<timestamp>.log files. A new log is created each time the server starts. A large collection of logs created at very short intervals is an indication that the conditions described in article 821438 exist on your server
===========================