Calling Connection not ActiveConnection

Results 1 to 2 of 2

Thread: Calling Connection not ActiveConnection

  1. #1
    Join Date
    Dec 1969

    Default Calling Connection not ActiveConnection

    I&#039;m still not getting the idea of how to call the command using the connection already created. This works but I am calling ActiveConnection. How would you write this code calling the &#039;objConn.Open&#039; connection and not &#039;objCommand.ActiveConnection&#039;?<BR><BR>se t objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .Open = "dsn=Products;"<BR><BR>set objCommand = Server.CreateObject("ADODB.Command")<BR>objCommand .ActiveConnection = "dsn=Products;"<BR>objCommand.CommandText = sqlString<BR>objCommand.CommandType = 1<BR><BR>set objRS = objCommand.Execute<BR> While Not objRS.EOF<BR> custId = (objRS.Fields.Item("id").Value)<BR> objRS.MoveNext<BR> Wend<BR>objConn.Close<BR><BR>I know this is probably another stupid question but ya gotta be patient with us hillbillies.

  2. #2
    Join Date
    Dec 1969

    Default You will kick yourself...

    Just change this:<BR> objCommand.ActiveConnection = "dsn=Products;"<BR>to<BR> objCommand.ActiveConnection = objConn<BR><BR>That&#039;s all. Use the connection *OBJECT* that you created instead of the string.<BR><BR>You know, for *reading* data from a DB, you really do *NOT* want or need a Command object, at all. The code you show there could be done more simply as:<BR><BR>&#060;%<BR>set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .Open = "dsn=Products;"<BR><BR>set objRS = [hl="yellow"]objConn[/hl].Execute<BR>While Not objRS.EOF<BR> custId = objRS.Fields.Item("id").Value<BR> ... whatever you do with that ...<BR> objRS.MoveNext<BR>Wend<BR>objRS.Close &#039; should do this!<BR>objConn.Close <BR>%&#062;<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