.Net, ASP.NET, Data Sources, Database, Programming, Software, SQL, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Tips, Transact-SQL, tSQL, VB.NET, Visual Studio 2010, Web Development, XML

SQL Server – Pass a List from your ASP.NET Code to a Stored Procedure using XML

Sometimes while developing a tool, a developer needs to pass a list of values with a variable size to their database. There are several ways of doing so, one of which involves passing the list in XML format.

The introduction of SQL Server 2005 offered the use of XML datatypes, which had not existed in previous versions of SQL Server. The good thing about the XML datatype is that it is not just good for storing information in XML format, but also has advantages such as being fully query-able similar to a database table.

As you look through this example, please feel free to check out other articles I have written for more SQL Tips

Here are the three main ways of passing lists of parameters to the different versions of SQL Server

A big benefit of the XML datatype is the ability to pass lists of items to stored procedures as XML format parameters. In SQL Server 2000 one would have to pass a list of parameters as a String that would then need to be parsed into its components in the Stored Procedure. This a tedious process that could easily introduce parsing errors. Subsequent versions of SQL Server have added extra ways in which to pass information lists to Stored Procedures:

  1. As a character-separated list contained in a String (VARCHAR) variable – SQL Server 2000 +
  2. As an XML variable – SQL Server 2005 +
  3. As a table variable – SQL Server 2008 +

As you can see from the list above, the methods of passing lists to stored procedures have increased in number over the last few iterations of SQL Server. The catch of course is that as a developer you will need to adapt your code to whichever instance of SQL Server your project is based on.

Continue reading “SQL Server – Pass a List from your ASP.NET Code to a Stored Procedure using XML”

Advertisements
.Net, ADO.NET, ASP.NET, Data Sources, Error Handling, Programming

ASP.NET Error – Adding the specified count to the semaphore would cause it to exceed its maximum count

If you are working with ASP.NET in Visual Studio, then you may be mystified when you see an error code : Adding the specified count to the semaphore would cause it to exceed its maximum count.

This error had me wondering what exactly is going on… Continue reading “ASP.NET Error – Adding the specified count to the semaphore would cause it to exceed its maximum count”

Classic ASP, Data Sources, Programming, VBScript, Web Development

Classic ASP – Example of a Basic Database Connection (SQLOLEDB)

Classic ASP Revisited
Classic ASP Revisited

I’m revisiting some classic ASP functionality, and in this case I’m reviewing how to set up a simple database connection to a SQL Server database. There are of course several ways to get this to work, and in this case we will use the SQLOLEDB provider.

Classic ASP is Still Used and Maintained

There are many applications built 10+ years ago, or still being built using the classic ASP framework. In my opinion this was a solid and very usable framework. ASP has been supplanted long ago by the ASP.NET framework which qualifies as a full programming language with a vast library of functionality to call on. However ASP is still used and does provide a simple and efficient way to get the job done.

Continue reading “Classic ASP – Example of a Basic Database Connection (SQLOLEDB)”