Classic ASP Connection - asp-classic

In my asp project,i have two databases in MS Access.Below code is working fine.But I need to add one more database with another dsn name.I have created dsn name efg and done the ODBC Connection for new databse in the control panel->Administrative tools.How can add the newly added dsn to the below code.
<%
session("connectionstring") = "dsn=abc"
set objconn = server.CreateObject("adodb.connection")
objconn.open session("connectionstring")
%>

Just create a second connection for the second dsn:
<%
' First dsn/connection
session("connectionstring") = "dsn=abc"
set objconn = server.CreateObject("adodb.connection")
objconn.open session("connectionstring")
' Second dsn/connection
session("connectionstring2") = "dsn=newDSN"
set objconn2 = server.CreateObject("adodb.connection")
objconn2.open session("connectionstring2")
%>

Related

Having issues connecting Access database with ASP/ADO

I am trying to connect to an access database with ADO. Below is my script. The access database is called ADOTesting1.mdb. I'm thinking it has to do with the path. This is where the file is located.
C:\inetpub\wwwroot\MyWeb
<%
Dim conn
Dim rs
Dim rdsql
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/MyWeb/ADOTesting1.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
for each x in rs.fields
response.write(x.name)
response.write(" = ")
response.write(x.value)
next
%>
You will have to use Server.MapPath to map the physical path to the website path.
Instead of:
conn.Open "c:/inetpub/wwwroot/MyWeb/ADOTesting1.mdb"
Try:
conn.Open Server.MapPath("/MyWeb/ADOTesting1.mdb")
or whatever the relative path is to your web root "/".

How to push information to active directory with ASP

Can someone point me in the right direction for information on how to push data to Active Directory from Classic ASP?
There are a couple of ways this can be done from classic ASP.
Use ADO with ADSI
Use the ADSI Objects of LDAP
Here's a sample from Modifying an ADSI Object from ADO
'Replace department for all users in OU=sales.
Set con = Server.CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
Set command = CreateObject("ADODB.Command")
Set command.ActiveConnection = con
command.CommandText = "SELECT AdsPath, cn FROM 'LDAP://OU=Sales,DC=Fabrikam,DC=com' WHERE objectClass = 'user'"
command.Properties("searchscope") = ADS_SCOPE_ONELEVEL
Set rs = command.Execute
While Not rs.EOF
Set usr = GetObject(rs.Fields("AdsPath").Value)
usr.Put "department", "1001"
usr.SetInfo
rs.MoveNext
Wend
Here's a sample from the article Getting Started with ASP for ADSI.
<%# Language=VBScript %>
<%
' Get the inputs.
containerName = Request.Form("inpContainer")
' Validate compName before using.
If Not ("" = containerName) Then
' Bind to the object.
adsPath = "LDAP://" & containerName
Set comp = GetObject(adsPath)
' Write the ADsPath of each of the child objects.
Response.Write("<p>Enumeration:</p>")
For Each obj in comp
Response.Write(obj.ADsPath + "<BR>")
Next
End If
%>

Save ASP classic form into a specific column in excel

I'd to know if it's possible to have my asp classic form saved into a excel file in a column after submit?
Thank you all.
use the Microsoft.Jet.OLEDB Driver to access the excel sheet like so:
dim conn : set conn = server.createObject("ADODB.Connection")
dim rs : set rs = server.createObject("adodb.recordset")
dim sql
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
"myExcelFile.xls;" &_
"Extended Properties=""Excel 8.0;HDR=YES;"""
then you yould use just sql to insert your data...
the possible connectionstrings for excel are listed here
THE BELOW CODE IS TO INSERT INTO AN EXISTING EXCEL FILE. THIS IS WHAT YOU NEED.
<%
Option Explicit
' OPEN DATABASE
dim objConn,strConnection,objRS,strQuery
'Set objConn = New ADODB.Connection
set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TEST.xls") & "; Extended Properties=Excel 8.0;"
objConn.Open strConnection
'Set objRS = New ADODB.Recordset
set objRS = Server.CreateObject("ADODB.Recordset")
set objRS.ActiveConnection = objConn
' This is to Select A1:A1 and open the recordset
strQuery = "SELECT * FROM A1:A1"
objRS.Open strQuery
' This is to insert into A1:A1 a value that says: testttest
strQuery = "insert into [A1:A1] values('testttest')"
' Close and destroy the Connection object.
objConn.Execute strQuery
objConn.Close
Set objRS=Nothing
Set objConn=Nothing
%>
TO UPDATE A SPECIFIC COLUMN
You can do this: See here: http://bytes.com/topic/asp-classic/answers/620074-update-existing-excel-file-using-asp-urgent
and also here: Update Excel Sheet (in Classic ASP/Vbscript)

asp question ADODB.Recordset and calling a procedure

I have to make an quick update on a legacy asp page never really having done anything with classical asp want to check if this is valid.
Can I do this:
set conn = server.CreateObject("ADODB.Connection")
conn.Open ("connection string info")
Set rsIdent = server.CreateObject("ADODB.Recordset")
SQL = "EXEC procedureName #sParam = '" & someVariable & "'"
rsIdent.Open SQL, conn
iSome_ID = rsIdent.Fields("ident_value")
rsIdent.Close()
Set rsIdent = nothing
Where procedureName is a stored procedure that accepts a paramter, does some processing and returns a single record in a column called "ident_value"?
#Curtis: See How to call SQL Server stored procedures from ASP.

how do i retrieve data from SQLite to VB6?

i am using SQLite3 ODBC Driver as my connection string,
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=test.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
conn.Open
rs.Open "select * from Artists", conn, adOpenDynamic, adLockOptimistic
MsgBox rs.Fields(0)
Refer here for the connection string properties:
http://www.connectionstrings.com/sqlite
You should also specify the version (3 or 2).
Edit: try to remove: LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0
And add the version: version=3
If it works, try to add a property at a time until it won't work anymore, to identify the broken property.
These are available connect string options for SQLite3 ODBC Driver
Description=
Database=<<file_name>
Timeout=
StepAPI=0
SyncPragma=
NoTXN=0
ShortNames=0
LongNames=0
NoCreat=0
NoWCHAR=0
FKSupport=0
LoadExt=
I just created a system DSN and looked in registry at HKLM\SOFTWARE\ODBC\ODBC.INI\<<my_dsn_here>>

Resources