Solved

Example Of Database Connection using ADO Parameters

Posted on 2008-06-23
6
514 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:
Kelvin McDaniel 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 informatio…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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