Click to See Complete Forum and Search --> : Classic ASP connect to SQL 2008?


Danbabe
12-09-2009, 08:46 AM
I thought it was about time I upgraded by database skills. I currently have classic ASP web sites connecting to Access databases. This is the connection script I use in an Include File to connect to MS Access locally on the web server:

<!--#include file="includes/ADOVBS.inc" -->
<%
Dim RS, Connect
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Provider = "Microsoft.Jet.OLEDB.4.0;"
Connect.Properties("Jet OLEDB:Database Password") = "asecurestart"
Connect.Open "Data Source=DBPath\cgi-bin\DBName.mdb;"

Set RS = Server.CreateObject("ADODB.Recordset")
%>

This all works perfectly but I understand connecting to a SQL database is completley different.

Has anyone got the code to connect to a SQL database on a seperate server on the local LAN called SQL1? I am a complete novice to SQL so some help would be much appreciated indeed!

Many thanks

Dan

yamaharuss
12-11-2009, 07:57 AM
This is all you need:

Set Conn=Server.CreateObject("ADODB.Connection")
"PROVIDER=SQLOLEDB;DATA SOURCE=myIPAddress;DATABASE=myDatabase;USER ID=myUserID;PASSWORD=myPassword;"

Then when you query, use this:

sql = "SELECT * FROM WhateverTable"
Set rs=Conn.Execute(sql)