Frontpages Web Hosting Support

ASP SQL Database Connection

You must have a working knowledge of programming with active server pages (ASP), designing MS SQL 2000 databases and HTML to use this information. This information falls under web development, which is not part of free support. This information is provided as a service to our web hosting customers and is provided as-is.

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 ----


Learn more about ASP at Frontpage's ASP Support page.


Enjoy hassle-free, expert ASP.net hosting from Fpweb.net.