<p>Currently I run an classic (old) ASP webpage with recordset object used directly in bad old spagethi code fasion.</p>

<p>I'm thinking of implementing a data layer in asp.net as web serivce to improve manageability. This is also a first step towards upgrading the website to asp.net.
The site itself remains ASP for the moment...</p>

<p>Can anybody recommend a good way of replacing the recordset object type with a web service compatible type (like an array or something)?
What do I replace below with?:</p>

<pre><code>set objRS = oConn.execute(SQL)
while not objRS.eof
   ...
   name = Cstr(objRS(1))
   ...
wend
</code></pre>

<p>and also mutliple recordsets can be replaced with?
I'm talking :</p>

<pre><code> set objRS = objRs.nextRecordset 
</code></pre>

<p>Anybody went through this and can recommend?</p>

<p><strong><em>@AdditionalInfo - you asked for it :-)</em></strong></p>

<p>Let me start at the beginning. 
<strong>Existing Situation is</strong>:
I have an old ASP website with classical hierachical content (header, section, subsection, content) pulled out of database via stored procedures and content pages are in database also (a link to html file).</p>

<p>Now bad thing is, ASP code everywhere spread over many .asp files all doing their own database connections, reading, writing (u have to register for content). Recently we had problems with SQL injection attacks so I was called to fix it.</p>

<p>I <em>could</em> go change all the .asp pages to prevent sql injection but that would be madness. So I thought build a data layer - all pages using this layer to access database. Once place to fix and update db access code.</p>

<p>Coming to that decision I thought asp.net upgrade isn'f far away, why not start using asp.net for the data layer? This way it can be re-used when upgrading the site.</p>

<p>That brings me to the questions above!</p>

[{'answer_id': 55358, 'author': 'Euro Micelli', 'author_id': 2230, 'author_profile': 'https://Stackoverflow.com/users/2230', 'pm_score': 2, 'selected': False, 'text': "<p>First my favorite advice of this week: do not treat your Web Service like it if was a local object or you are going to pay a very hefty performance price. Essentially, don't do things like this in your web application:</p>\n\n<pre><code>MyDataWebService ws = new MyDataWebService();\nforeach(DataItem item in myData)\n{\n    ws.Insert(item);\n}\n</code></pre>\n\n<p>You should always prefer to minimize calls to your Web Service (and SQL):</p>\n\n<pre><code>MyDataWebService ws = new MyDataWebService();\nws.Insert(myData); // Let the web service process the whole set at once.\n</code></pre>\n\n<p>Now, as far as the data type to use for your web service calls, you basically have two choices:</p>\n\n<ul>\n<li>DataSet</li>\n<li>Everything else (Array)</li>\n</ul>\n\n<p>Most collections returned from a web service (like a List&lt;MyData&gt;) actually convert to an Array during the Web Service invocation. Remember that Web Services don't return objects (data + behavior) but just data structures (or a sequence of). Therefore, there is little distinction between a List and an Array.</p>\n\n<p>DataSets are more complex classes; they use their own custom serializer and pretty much get fully recreated in the calling application. There is a cost in performance to be paid for using DataSets like that, so I don't usually recommend it for most scenarios. Using arrays to pass data back and forth tends to be more efficient, and quite frankly it's easier to do.</p>\n\n<p>Your case is a bit different; because you are converting an existing site that already uses ADO, an ADO.NET DataSet might be your best updgrade path. ADO.NET and ADO are similar enough that a straight update might be easier that way. It kind of depends how your web site is built.</p>\n\n<p>For the last part of your question, DataSets do support multiple recordsets similar to ADO's Recordset. They are called DataTables. Every DataSet has at least one DataTable and you can read them in any order.</p>\n\n<p>Good luck.</p>\n"}, {'answer_id': 55378, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 1, 'selected': False, 'text': '<p>I\'d suggest using the XmlHttp class in your ASP code.</p>\n\n<p>Assuming you have an ASMX web service similar to this, in MyService.asmx:</p>\n\n<pre><code>[WebMethod]\npublic string HelloWorld()\n{\n  return "Hello World";\n}\n</code></pre>\n\n<p>You could call it in ASP something like this:</p>\n\n<pre><code>Dim xhr\n\nSet xhr = server.CreateObject("MSXML2.XMLHTTP")\n\nxhr.Open "POST", "/MyService.asmx/HelloWorld", false\nxhr.SetRequestHeader "content-type", "application/x-www-form-urlencoded"\nxhr.Send\n\nResponse.Write(xhr.ResponseText)\n</code></pre>\n\n<p>ResponseText would be an XML response of:</p>\n\n<pre><code>&lt;string&gt;Hello World&lt;/string&gt;\n</code></pre>\n\n<p>Assuming your service returned a collection of data, you could iterate over it using XPath or any other XML processing technique/library.</p>\n\n<p>Googling around about MSXML2 will probably answer any specific questions you have, since it\'s specific to ASP classic.</p>\n'}, {'answer_id': 55588, 'author': 'DancesWithBamboo', 'author_id': 1334, 'author_profile': 'https://Stackoverflow.com/users/1334', 'pm_score': 1, 'selected': False, 'text': '<p>Instead of thinking in layers, why not try taking vertical slices through the application and converting those to .net.  That way you will get entire features coded in .net instead of disjoint parts.  What is the business value in replacing perfectly working code without improving the user experience or adding features?</p>\n\n<p>You might also consider the trade-off of performance you are going to give up with a Web Service over direct ado calls.  Web Services are a good solution to the problem of multiple disjoint applications/teams accessing a common schema; they do not make a single isolated application more maintainable, only slower and more complex.</p>\n'}, {'answer_id': 75703, 'author': 'Skyhigh', 'author_id': 13387, 'author_profile': 'https://Stackoverflow.com/users/13387', 'pm_score': 2, 'selected': True, 'text': '<p>If you wanted to stick with Classic ASP then I would suggest creating a Database handling object via ASP Classes then just use that object to do your recordset creations.  This would centralize your database handling code and make it so that you only have to handle SQL Injection attacks in a single location.</p>\n\n<p>A simple example.</p>\n\n<pre><code>Class clsDatabase\n\n    Private Sub Class_Initialize()\n        If Session("Debug") Then Response.Write "Database Initialized&lt;br /&gt;"\n    End Sub\n\n    Private Sub Class_Terminate()\n        If Session("Debug") Then Response.Write "Database Terminated&lt;br /&gt;"\n    End Sub\n\n    Public Function Run(SQL)\n        Set RS = CreateObject("ADODB.Recordset")\n        RS.CursorLocation = adUseClient\n        RS.Open SQLValidate(SQL), Application("Data"), adOpenKeyset, adLockReadOnly, adCmdText\n        Set Run = RS\n        Set RS = nothing\n    End Function\n\n    Public Function SQLValidate(SQL)\n        SQLValidate = SQL\n        SQLValidate = Replace(SQLValidate, "--", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, ";", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, "SP_", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, "@@", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, " DECLARE", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, "EXEC", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, " DROP", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, " CREATE", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, " GRANT", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, " XP_", "", 1, -1, 1)\n        SQLValidate = Replace(SQLValidate, "CHAR(124)", "", 1, -1, 1)\n    End Function\nEnd Class\n</code></pre>\n\n<p>Then to use this you would change your calls to:</p>\n\n<pre><code>Set oData = new clsDatabase\nSet Recordset = oData.Run("SELECT field FROM table WHERE something = another")\nSet oData = nothing\n</code></pre>\n\n<p>Of course you can expand the basic class to handle parametrized stored procedures or what not and more validations etc. </p>\n'}, {'answer_id': 79876, 'author': 'Mike Henry', 'author_id': 14934, 'author_profile': 'https://Stackoverflow.com/users/14934', 'pm_score': 1, 'selected': False, 'text': '<p>Another alternative is to use COM Interop to create an assembly in .NET that is callable from classic ASP.</p>\n\n<p>To create a COM Interop assembly from Visual Studio (e.g. Microsoft Visual C# 2005 Express Edition):</p>\n\n<ul>\n<li>Create a new Class Library project</li>\n<li><p>Open the project properties</p>\n\n<ul>\n<li>Under Application select Assembly Information... and enable "Make assembly COM-Visible"</li>\n<li>Under Signing enable Sign the assembly and create or select an existing strong name key file</li>\n</ul></li>\n<li><p>Write and build the library</p>\n\n<ul>\n<li>COM Interop classes must have a default constructor and only non-static classes and methods are published</li>\n</ul></li>\n<li><p>Copy the .dll to the desired folder/machine</p></li>\n<li>Register the .dll for COM using RegAsm</li>\n</ul>\n\n<p>For example (adjust as necessary):</p>\n\n<pre><code>"C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\RegAsm.exe" "C:\\path\\to\\assembly.dll" /tlb /codebase\n</code></pre>\n\n<ul>\n<li>Call the assembly from ASP</li>\n</ul>\n\n<p>For example (adjust as necessary):</p>\n\n<pre><code>Dim obj, returnValue\nSet obj = Server.CreateObject("MyProject.MyClass")\nreturnValue = obj.DoSomething(param1, param2)\n</code></pre>\n\n<p>Note:</p>\n\n<ul>\n<li>the assembly must be re-registered via RegAsm when it\'s updated</li>\n</ul>\n\n<p>See also:</p>\n\n<ul>\n<li><a href="http://msdn.microsoft.com/en-us/library/zsfww439(VS.71).aspx" rel="nofollow noreferrer">Exposing .NET Framework Components to COM (MSDN)</a></li>\n<li><a href="http://www.codeproject.com/KB/dotnet/dotnetcomponentandasp.aspx" rel="nofollow noreferrer">CodeProject: Call a .NET component from an ASP Page</a></li>\n</ul>\n'}, {'answer_id': 110377, 'author': 'DancesWithBamboo', 'author_id': 1334, 'author_profile': 'https://Stackoverflow.com/users/1334', 'pm_score': 1, 'selected': False, 'text': '<p>Sql injection should be handled by using parametrized sql queries.  Not only will this eliminate the security risk but it will significantly speed up your database performance because it will be able to reuse an execution plan instead of recalcing it every time.  The suggestion to handle it through string replacements is foolish.  VB is terrible at handling strings and those "replace" statements will be extremely costly in performance and memory (also, you actually only need to handle the \' character anyway)  </p>\n\n<p>Moving code to .net doesn\'t make it better.  Having db code in your pages isn\'t bad; especially if id you are talking about a small site with only a couple devs.  Thousands of sites use that technique to process bazillions of dollars in transactions.  Now, unparameterized dynamic sql is bad and you should work to eliminate that, but that doesn\'t require a rewrite of the app or .net to do it.  I\'m always curious why people see .net as a defacto improvement to their app.  Most of the bad code and bad habits that existed in the COM model just propagate forward during a conversion.  </p>\n\n<p>You either need to make a commitment to creating a truly cohesive, minimally coupled, OO design; or just keep what you have going because it isn\'t all that bad.</p>\n'}, {'answer_id': 4768697, 'author': 'alexsts', 'author_id': 552446, 'author_profile': 'https://Stackoverflow.com/users/552446', 'pm_score': 1, 'selected': False, 'text': '<p>Too bad I did not see this question in 2008.\nFor me it looks like your site is using Justa framework.\nSimple way is to modify Justa code for submit of search and data inputs to urlencode.\nI did it and work perfectly for me.</p>\n\n<p>Rest of the code secure enough to prevent any type os SQL injections or other attempt to get into database.</p>\n'}]
['https://Stackoverflow.com/questions/55297', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/925/']