• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

conntecting asp with sql serever

i have windows 2000 prof and sql serever 2000
i want to give me how i can conntected it?
and source code?
thanks
0
saria
Asked:
saria
1 Solution
 
sariaAuthor Commented:
thenks
0
 
John844Commented:
you need to use ado to connect to a db using an asp page.
a simple example would be something like

dim con
dim rs
dim strSQL

'define what data you wish to use
strSQL = "SELECT * FROM tableName"

'open a connection to the database
con.open <database connection string>

'open a recordset using the connection and SQL statement
rs.open strSQL, con, 3, 1

if rs.eof and rs.bof then
    response.write "No records returned.<br>"
else
    while not rs.eof
        'work with the data here
        'access the individual fields by placing their name in quotes like
        response.write rs("fieldName")
        rs.movenext
    loop
end if

rs.close
con.close

set rs = nothing
set con = nothing




Connection String
here is a link to help explain how to build a connection string
http://www.asp101.com/articles/john/connstring/default.asp

http://www.able-consulting.com/ADO_Conn.htm


if you want to use a DSN you can use
 con.open "FileDSN=SomeFileDSN"
or
 con.open "DSN=SomeSystemDSN"
or

0
 
daveamourCommented:
Dim objADOConnection
Dim rsData
Dim strSQL

Set objADOconnection = Server.CreateObject("ADODB.Connection")
Set rsData = Server.CreateObject("ADODB.Recordset")

objADOConnection.Open "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=Servername;DATABASE=Databasename;UID=Username;PWD=Password"

strSQL = "Select * From tableName"

rsData.Open strSQL, objADOConnection

While Not rsData.EOF
  Response.Write rsData.Fields("Fieldname") & "<Br>"
  rsData.Movenext
Wend  

Replace teh following with values appropriate to your database


Servername
Databasename
Username
Password
tableName
Fieldname

Hope this helps

Dave
0
 
AtsafrirCommented:
if you are working with windows 2000 - com+ you can use the Component consturct string. there is a good
exapmle for this in Fitch & Marther DNA sample application.
http://www.fmstocks.com download FMSTOCKS source code.
good luck.
if you want my DAL (Data Access Layer) component send me your email and i'll send it to you (it's better
then fmstocks).
there is a nice tool that you can use to ceate stored procedures , and cls file in vb (from which you
an create your component) to call the stored procedure
it's a freeware from lockwoodtech.
http://www.lockwoodtech.com/index_pbfree.htm
http://www.lockwoodtech.com/zips/ProcBlastFree.exe
0
 
MoondancerCommented:
I am sorry to see that Asker has not returned to update and finalize this question.  I am, therefore, force accepting this question.  In the event the Asker returns with additional needs related to this question, please respond and continue the collaboration process.
 
If there are questions in this regard, please comment and I'll return when I can.
 
The HELP DESK link on the left is informative, and includes this site's Guidelines and Member Agreement as well as assistance related to Questions and Answers.  Here is the QA link, as a reference.
 
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
 
Thank you,
Moondancer
Community Support Moderator @ Experts Exchange
 
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now