Solved

Example Of Database Connection using ADO Parameters

Posted on 2008-06-23
6
505 Views
Last Modified: 2008-06-24
Hi All

Please could someone provide me with an example ASP database connection string to a SQL Server 2000 database and 1 ADO parameter which loads the data into a recordset.

Many thanks,

Rit
0
Comment
Question by:rito1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21845444
0
 
LVL 1

Author Comment

by:rito1
ID: 21845545
Hi angellll,

The parameters need to be passed into a stored procedure and also 1 minor detail I missed was - I am using VBScript.. Sorry!

Rit
0
 
LVL 3

Expert Comment

by:darkmooink
ID: 21845552
i dont do it that way i use this way
Set DBatd = Server.CreateObject("ADODB.Connection")
DBcon.Open "Provider=SQLOLEDB; Server=192.168.1.1; Database=database name; UID=userid; PWD=password;"
 
Set Results = DBCon.Execute("select * from table1")

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Expert Comment

by:darkmooink
ID: 21845560
ops line 1 should be Set DBcon
0
 
LVL 1

Author Comment

by:rito1
ID: 21845860
Hi,

The reason I was doing it with parameters was that I have been stunk by an SQL injection attack previous so wanted to use ADO parameters to declare them.

Here is the code I have so far... I just can't figure out how to load the data into a recordset:

Set cn = Server.CreateObject("ADODB.Connection")
   cn.Open strDSNless
   Set cmd = Server.CreateObject("ADODB.Command")
   Set cmd.ActiveConnection = cn
   cmd.CommandText = "sp_SELECTCustomers"
   cmd.CommandType = adCmdStoredProc
   
   cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _
      adParamInput)
   ' Set value of Param1 of the default collection to 22
   cmd("Param1") = 22
   cmd.Execute
0
 
LVL 11

Accepted Solution

by:
azarc3 earned 500 total points
ID: 21847335
Try This...

[BEGIN] ------------------------------------------------------------------------------------

' *** This basis code is from your last comment on 06.23.2008 @ 09:18am EDT ***
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open strDSNless
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cn
cmd.CommandText = "sp_SELECTCustomers"
cmd.CommandType = adCmdStoredProc
   
cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _
      adParamInput)
' Set value of Param1 of the default collection to 22
cmd("Param1") = 22

' *** Delete the cmd.Execute and replace it with the following ***
Set oRS = Server.CreateObject("ADODB.RecordSet")
oRS.CursorLocation = 3
oRS.Open cmd

[END  ] ------------------------------------------------------------------------------------
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question