Method of Opening a recordset

Results 1 to 2 of 2

Thread: Method of Opening a recordset

  1. #1
    Join Date
    Dec 1969

    Default Method of Opening a recordset

    In almost every instance or example where a database is being opened and a recordset being populated, I see an instance of the Connection object being created. <BR><BR>The way I&#039ve always done my connection was to simply instantiate a recordset object and pass the SQL string and DSN name to it, along with cursor types.<BR><BR>example:<BR><BR>Set rsGetData = Server.CreateObject("ADODB.Recordset")<BR>strSQL = "SELECT fld_Blah FROM tbl_Blah...."<BR>rsGetData.Open strSQL, "DSNname", 1, 3 ,1<BR><BR>and this works for me everytime. <BR><BR>Is this an accepted method, and are there any downfalls to doing it this way as opposed to creating Connection object, Command objects etc?<BR><BR>thanks!<BR><BR>ed

  2. #2
    Join Date
    Dec 1969

    Default Actually, hidden opening of connection

    If you only open one RecordSet per ASP page, it is perfectly okay to also create the connection when you open the RecordSet. (And make no mistake, you *are* creating a Connection object via that just done automatically for you.)<BR><BR>However, if you open more than one RecordSet in a page (or possibly even close and re-open the same RecordSet object), then doing it your way is a mistake.<BR><BR>As mentioned, the RecordSet.Open automatically creates a Connection object and opens it under the covers. Opening a connection is often a *very* expensive proposition (in terms of resources, performance, etc.), so you *really* only want to create and open one connection per page. In which case the "standard" way is much the better way.<BR><BR>Okay?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts