This is great article by Karl Seguin about proper exception handling:
Understanding and Using Exceptions
Here are the key points:
- Don't catch exceptions unless you can actually handle them
- Do know how to rethrow exceptions properly
- Do use using or try/finally often
- Don't swallow exceptions
- Do use a global handler to help you log and display a friendly error message
---
Exception handling in .Net (some general guidelines) by Marc Brooks.
---
Keywords: ASP.NET 2.0, C#, VB.NET
Wednesday, July 05, 2006
Q: How could I quickly pass array from business layer (e.g. ASP.NET 2.0) to MS SQL Server 2005?
A: Pass XML to Stored Procedure.
SQL Server - No Arrays? No Problem!
1) Prepare XML string like this:
<data>
<meta>
<key>Key1</key>
<value>Value1</value>
</meta>
<meta>
<key>Key2</key>
<value>Value2</value>
</meta>
</data>
2) Pass it to Stored Procedure:
command.Parameters.Add("@Tags", SqlDbType.Xml).Value = NameValueToXml(post.Tags)
3) Stored Procedure:
CREATE PROCEDURE SavePost
(
...
@Tags XML
)
AS
...
INSERT INTO Xxx
SELECT ItemData.row.value('key[1]', 'varchar(200)'),
ItemData.row.value('value[1]', 'varchar(200)')
FROM @Tags.nodes('/data/meta') ItemData(row)
A: Pass XML to Stored Procedure.
SQL Server - No Arrays? No Problem!
1) Prepare XML string like this:
<data>
<meta>
<key>Key1</key>
<value>Value1</value>
</meta>
<meta>
<key>Key2</key>
<value>Value2</value>
</meta>
</data>
2) Pass it to Stored Procedure:
command.Parameters.Add("@Tags", SqlDbType.Xml).Value = NameValueToXml(post.Tags)
3) Stored Procedure:
CREATE PROCEDURE SavePost
(
...
@Tags XML
)
AS
...
INSERT INTO Xxx
SELECT ItemData.row.value('key[1]', 'varchar(200)'),
ItemData.row.value('value[1]', 'varchar(200)')
FROM @Tags.nodes('/data/meta') ItemData(row)
Q: How could I quickly pass array from business layer (e.g. ASP.NET 2.0) to MS SQL Server 2005?
SQL Server - No Arrays? No Problem!
1) Prepare XML string like this:
<data>
<meta>
<key>Key1</key>
<value>Value1</value>
</meta>
<meta>
<key>Key2</key>
<value>Value2</value>
</meta>
</data>
2) Pass it to Stored Procedure:
command.Parameters.Add("@Tags", SqlDbType.Xml).Value = NameValueToXml(post.Tags)
3) Stored Procedure:
CREATE PROCEDURE SavePost
(
...
@Tags XML
)
AS
...
INSERT INTO Xxx
SELECT ItemData.row.value('key[1]', 'varchar(200)'),
ItemData.row.value('value[1]', 'varchar(200)')
FROM @Tags.nodes('/data/meta') ItemData(row)
SQL Server - No Arrays? No Problem!
1) Prepare XML string like this:
<data>
<meta>
<key>Key1</key>
<value>Value1</value>
</meta>
<meta>
<key>Key2</key>
<value>Value2</value>
</meta>
</data>
2) Pass it to Stored Procedure:
command.Parameters.Add("@Tags", SqlDbType.Xml).Value = NameValueToXml(post.Tags)
3) Stored Procedure:
CREATE PROCEDURE SavePost
(
...
@Tags XML
)
AS
...
INSERT INTO Xxx
SELECT ItemData.row.value('key[1]', 'varchar(200)'),
ItemData.row.value('value[1]', 'varchar(200)')
FROM @Tags.nodes('/data/meta') ItemData(row)
ASP.NET 2.0 Global Event handling: HttpModules
Global.asax? Use HttpModules Instead! by Karl Seguin
namespace Fuel.Web
{
public class ErrorModule : IHttpModule
.....
}
Web.config:
<httpModules>
<add name="ErrorModule" type="Fuel.Web.ErrorModule, Fuel.Web" />
</httpModules>
namespace Fuel.Web
{
public class ErrorModule : IHttpModule
.....
}
Web.config:
<httpModules>
<add name="ErrorModule" type="Fuel.Web.ErrorModule, Fuel.Web" />
</httpModules>
Subscribe to:
Posts (Atom)