Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Connect SQL With ASP Pages

Status
Not open for further replies.

dapoV

Programmer
Jul 5, 2002
2
ZA
I want to connect SQL with ASP Pages. Can any with idea help me. Your help is highly appreciated. HOLA HOLA HOLA ME!!!!!!!!!!!!! SEVEN DOWN
 
Hi,

the code will be something like this.
Dim spConnectionString
dim adoconnection
dim rs

spConnectionstring = "Driver={SQL Server};Server=Server Name;UID=User Name for SQL SERVER;PWD=Password for SQL SERVER;Database=Database Name;"

set adoconnection =Server.CreateObject("ADODB.Connection")
adoconnection.ConnectionString = spConnectionstring
adoconnection.Open


SQL = " SELECT * from tablename" ''' Open Any table in the DB
rs.Open SQL, adoconnection '' Open a recordset

Sunil
 

ASP named Connect.asp

<!--Establish a generic Logon, connection to the Frigdare database -->

<%

Dim objLogon
Dim conn

Set objLogon = Server.CreateObject(&quot;Impersonate.ImpersonateUser&quot;)

objLogon.Logon &quot;iusr_apps_server2&quot;, &quot;threepeaks&quot;, &quot;Springfield&quot;


set conn = server.createobject(&quot;adodb.connection&quot;)
conn.open &quot;Provider=SQLOLEDB.1;Integrated Security=SSPI;&quot; & _
&quot;Persist Security Info=False;Initial Catalog=frigdare;&quot; & _
&quot;Data Source=D_Ship_Server1&quot;
set session(&quot;user_conn&quot;) = conn

%>



Then in the other ASP that reads data:

<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<% Option Explicit %>

<!--#include file=&quot;adovbs.inc&quot;-->
<!--#include file=&quot;Connect.asp&quot;-->


<%
Dim rs
Dim sql

sub SelectData(selectyr)

sql = &quot;SELECT ItemCount, Carrier FROM LoadHist WHERE year(DateClosed) = '&quot; & selectyr & &quot;' AND month(DateClosed) = '&quot; & intmon & &quot;'&quot;

set rs = createobject(&quot;adodb.recordset&quot;)

rs.open sql,conn, adOpenStatic, adLockReadOnly, adCmdText
.
.
end sub

maybe this will get you started. John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top