• Sales: 866.780.4678
  • Sales Chat
  • Get a Quote
Microsoft Partner of the Year Award
Hosting Solutions - 2010 Finalist
you are here:
Fpweb.net
Support
Asp Sql
asp Sql Database Connection
 
 

ASP SQL Database Connection

You must have a working knowledge of programming with active server pages (ASP), designing MS SQL databases and HTML to use this information. Web development is not part of free support, but we provide as much information as possible online to assist our customers with Development issues they face. Learn more about ASP at Fpweb.net's ASP Resources page.

For sake of understanding on how you modify the code below for your use, we will use the following (items, in bold, are what you change):

  • SQL Server IP Address =11.111.11.111
  • SQL user name = myusername
  • SQL password = mypwd
  • SQL database name = mysqldatabase
  • Table in database = mysqltable
  • Column in mysqltable = lastname
 

ASP Source Code (ASP 3.0 & VBScript)

The ASP code begins with <% and ends with %>, which is required.

Download the code (change to an .asp extension)

–––– code begins under this line of text ––––

<%@ Language=VBScript %>

<%

Dim conn

set conn = Server.CreateObject("ADODB.Connection")

conn.ConnectionString = "driver={SQL Server};" & _

"server=11.111.11.111;" & _

"Address=11.111.11.111,1433;" & _

"Network=DBMSSOCN;" & _

"uid=myusername;" & _

"pwd=mypwd;" & _

"database=mysqldatabase;"

Dim strSQL, rs

strSQL = "Select lastname from  mysqltable"

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open strSQL, conn

Response.Write "<h1>Connection Works!</h1>"

Response.Write "<h2>Database Records Below</h2>"

do while not rs.EOF

Response.Write rs("lastname")

Response.Write "<BR>"

rs.MoveNext

loop

rs.Close

Set rs = Nothing

conn.Close

Set conn = Nothing

%>


–––– code ends above this line of text ––––

 
 

Get expert I.T. service for your hosted data with managed dedicated hosting from Fpweb.net.




 
close
close
close
close