Connecting to SQL server

Results 1 to 2 of 2

Thread: Connecting to SQL server

  1. #1
    Join Date
    Dec 1969

    Default Connecting to SQL server

    I am trying to connect to a sql server database called TEST, the table i am thryng to access is called staff, could you please help?? I need the code to make the link between the database and the ASP pages, to query tables...

  2. #2
    Join Date
    Dec 1969

    Default RE: Connecting to SQL server

    First of all, next time please read the Faqs. This is really basic, but since I&#039;m in a good mood here you go ;-)<BR><BR>&#060;%<BR>dim connstring<BR>connstring = "Provider=sqloledb.1;Data Source=SERVERNAME;Initial Catalog=TEST;User Id=xxx;Password=xxx;"<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .Open connstring<BR>%&#062;<BR><BR>You now have an open connection to your DB. To query the DB you could do:<BR>&#060;%<BR>SET rs = objConn.Execute("SELECT * FROM staff")<BR><BR>Do Until rs.eof<BR> response.write rs("Firstname")<BR>Loop<BR><BR>&#039;Close the connection and recordset<BR>rs.close<BR>set rs = nothing<BR>objConn.close<BR>set objConn = nothing<BR>%&#062;<BR><BR>This is an very basic example. I would like to sugggest to do a little more R&D into DB connectivity<BR><BR>Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts