Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 16, 2012, 05:18:33 PM

Pages: [1]   Go Down
  Print  
Author Topic: ASP Connection String for SQL Server  (Read 2064 times)
hw15
Spacescooter Operator
*****
Offline Offline

Posts: 36



WWW
« on: July 12, 2008, 12:36:54 PM »

Hello, just wanted to offer a refresher for anyone who wants to connect to a SQL database with classic ASP on Lunarpages. If you have a Plesk account then you can create a new SQL database there. You can manage your database with MyLittleAdmin tool.

You have a database setup as follows:

Database Server: 209.200.235.3
Database Name: myDatabase
Database User: myUser
Database Password: myPassword

You have a table setup as follows:

TableName: myTable
ColumnName: myColumn
Datatype: varchar

You have sample data entered into the table:

Row 1: Hello World!
Row 2: John Doe

Now you want to display the records. Using your favorite web page editor like Dreamweaver, place the following code on a blank page called myTestPage.asp and upload it to the server via FTP.

<%
'open the connection
Dim Connect, myRecordSet
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open = "Provider=MSDASQL;Driver={SQL Server};Server=209.200.235.3;Database=myDatabase;Uid=myUser;Pwd=myPassword;"
%>

<%
'display the data
Set myRecordSet = Connect.Execute ("SELECT * FROM dbo.myTable")
do until myRecordSet.EOF
response.write(myRecordSet("myColumn")&"<br>")
myRecordSet.MoveNext
loop
%>


In the browser, go to www.myDomainName.com/myTestPage.asp . The output displayed will be:

Hello World!
John Doe

Lunarpages has at least two SQL Servers, Castor and Raptor. You can access Castor with 209.200.235.3 and http://lesuth.lunarpages.com/mylittleadmin . You can access Raptor with 209.200.244.115 and http://lesuth.lunarpages.com/mylittleadmin2 .

Warning: databases are highly vulnerable to hackers. The SQL injection attacks and XSS (cross-site scripting) attacks are running rampant. So please ensure you have setup custom error pages and use ASP input validation as a precaution to ensure database security. For more info, check out: http://www.ehow.com/how_4434719_protect-website-hacker-attacks.html .

Hope you may find this useful.

 Yep
« Last Edit: July 13, 2008, 02:47:20 PM by hw15 » Logged

Web development and consulting by Internet ArchiTECH.
Mitch
Berserker Poster
*****
Offline Offline

Posts: 12837


WWW
« Reply #1 on: July 14, 2008, 05:50:49 AM »

Thanks for sharing!   Thumbs Up
Logged

New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!
Pages: [1]   Go Up
  Print  
 
Jump to: