Solved

Example Of Database Connection using ADO Parameters

Posted on 2008-06-23
6
469 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
6 Comments
 
LVL 142

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now