Dossy,
I have a Linux box running nsfreetds! Both it and freetds seemed to build
correctly on the first try, and the server loads the module. Amazing it
worked for me. No problems with the C build, though I did use a binary of
AOLserver for Linux 2.2 from aolserver.com, for expediency. I set up the
interfaces file, the SYBASE and LIBPATH environment vars, and altered the
sample-config.tcl according to admin guide at aolserver.com. See listings
below.
I placed nsfreetds.adp in the pageroot, and altered it so my test SQL server
was in the dropdown. It gives me this when I submit a SELECT statement
against PUBS db:
===========
(If this is the only thing you see on the page, most likely there was an
error thrown in the server.log.)
Error connecting to datasource.
===========
There is no message at all in the server log when the page is hit. I have
the log on a console ( -f ).
My server is an MS SQL Server 7 so I use tds7.0.
I was forced to make a couple of guesses/assumptions when configuring it,
where the docs were sparse. One was "what goes in the ns_param Datasource
for the nsfreetds driver" ? I guessed the server name from the interfaces
file. Another was "what to pass to ns_db gethandle" ?
My mistake is probably something obvious to a more experienced eye...
Here's my interfaces file, followed by my sample-config.tcl, then my
nsfreetds.adp:
=======================================
markhpc
query tcp tds7.0 192.168.0.173 1433
=======================================
# $Header: /cvsroot/aolserver/aolserver/nsd/sample-config.tcl,v 1.2
2000/12/13 21:50:27 kriston Exp $
#
# sample-config.tcl -- The AOLserver Startup Script
#
# This is a Tcl script that is sourced when AOLserver starts up.
# A detailed reference is in "doc/config.txt".
#
ns_log notice "config.tcl: starting to read config file..."
#
# Set some Tcl variables that are commonly used throughout this file.
#
set httpport 80
set httpsport 443
# The hostname and address should be set to actual values.
set hostname aolvm
set address 192.168.0.7
set servername "server1"
set serverdesc "Server Name"
set homedir [file dirname [ns_info config]]
set bindir [file dirname [ns_info nsd]]
set pageroot ${homedir}/servers/${servername}/pages
set directoryfile index.adp,index.html,index.htm
set ext [info sharedlibextension]
# nsssl: Only loads if keyfile.pem and certfile.pem exist.
#set sslmodule nsssl${ext} ;# Domestic 128-bit/1024-bit SSL.
set sslmodule nsssle${ext} ;# Exportable 40-bit/512-bit SSL.
set sslkeyfile ${homedir}/servers/${servername}/modules/nsssl/keyfile.pem
set sslcertfile ${homedir}/servers/${servername}/modules/nsssl/certfile.pem
# nscp: Uncomment the sample password and log in with "nsadmin", password
"x",
# type "ns_crypt newpassword salt" and put the encrypted string below.
set nscp_port 9999
set nscp_addr 127.0.0.1
set nscp_user ""
#set nscp_user "nsadmin:t2GqvvaiIUbF2:" ;# sample user="nsadmin", pw="x".
#
# Global server parameters
#
ns_section "ns/parameters"
ns_param home $homedir
ns_param debug false
#
# Thread library (nsthread) parameters
#
ns_section "ns/threads"
ns_param mutexmeter true ;# measure lock contention
#ns_param stacksize [expr 128*1024] ;# Per-thread stack size.
#
# MIME types.
#
# Note: AOLserver already has an exhaustive list of MIME types, but in
# case something is missing you can add it here.
#
ns_section "ns/mimetypes"
ns_param default "*/*" ;# MIME type for unknown extension.
ns_param noextension "*/*" ;# MIME type for missing extension.
#ns_param ".xls" "application/vnd.ms-excel"
############################################################
#
# Server-level configuration
#
# There is only one server in AOLserver, but this is helpful when multiple
# servers share the same configuration file. This file assumes that only
# one server is in use so it is set at the top in the "server" Tcl
variable.
# Other host-specific values are set up above as Tcl variables, too.
#
ns_section "ns/servers"
ns_param $servername $serverdesc
#
# Server parameters
#
ns_section "ns/server/${servername}"
ns_param directoryfile $directoryfile
ns_param pageroot $pageroot
ns_param globalstats true ;# Enable built-in statistics.
ns_param urlstats true ;# Enable URL statistics.
ns_param maxurlstats 1000 ;# Max number of URL's to do stats on.
ns_param enabletclpages true ;# Parse *.tcl files in pageroot.
#
# Scaling and Tuning Options
#
# Note: These values aren't necessarily the defaults.
#
#ns_param connsperthread 0 ;# Normally there's one conn per
thread
#ns_param flushcontent false ;# Flush all data before returning
#ns_param maxconnections 100 ;# Max connections to put on queue
#ns_param maxdropped 0 ;# Shut down if dropping too many
conns
#ns_param maxthreads 20 ;# Tune this to scale your server
#ns_param minthreads 0 ;# Tune this to scale your server
#ns_param threadtimeout 120 ;# Idle threads die at this rate
# Directory listings -- use an ADP or a Tcl proc to generate them.
#ns_param directoryadp $pageroot/dirlist.adp ;# Choose one or the
other.
#ns_param directoryproc _ns_dirlist ;# ...but not both!
#ns_param directorylisting simple ;# Can be simple or fancy.
#
# ADP (AOLserver Dynamic Page) configuration
#
ns_section "ns/server/${servername}/adp"
ns_param map "/*.adp" ;# Extensions to parse as ADP's.
#ns_param map "/*.html" ;# Any extension can be mapped.
ns_param enableexpire false ;# Set "Expires: now" on all ADP's.
ns_param enabledebug false ;# Allow Tclpro debugging with
"?debug".
# ADP special pages
#ns_param errorpage ${pageroot}/errorpage.adp ;# ADP error page.
#
# ADP custom parsers -- see adp.c
#
ns_section "ns/server/${servername}/adp/parsers"
ns_param adp ".adp" ;# adp is the default parser.
#
# Socket driver module (HTTP) -- nssock
#
ns_section "ns/server/${servername}/module/nssock"
ns_param port $httpport
ns_param hostname $hostname
ns_param address $address
#
# Socket driver module (HTTPS) -- nsssl
#
# nsssl does not load unless sslkeyfile/sslcertfile exist (above).
#
ns_section "ns/server/${servername}/module/nsssl"
ns_param port $httpsport
ns_param hostname $hostname
ns_param address $address
ns_param keyfile $sslkeyfile
ns_param certfile $sslcertfile
#
# Control port -- nscp
#
# nscp does not load unless nscp_user is a valid user.
#
ns_section "ns/server/${servername}/module/nscp"
ns_param port $nscp_port
ns_param address $nscp_addr
ns_section "ns/server/${servername}/module/nscp/users"
ns_param user $nscp_user
#
# Access log -- nslog
#
ns_section "ns/server/${servername}/module/nslog"
ns_param rolllog true ;# Should we roll log?
ns_param rollonsignal true ;# Roll log on SIGHUP.
ns_param rollhour 0 ;# Time to roll log.
ns_param maxbackup 5 ;# Max number to keep around when
rolling.
#
# CGI interface -- nscgi
#
# WARNING: These directories must not live under pageroot.
#
ns_section "ns/server/${servername}/module/nscgi"
#ns_param map "GET /cgi /usr/local/cgi" ;# CGI script file dir (GET).
#ns_param map "POST /cgi /usr/local/cgi" ;# CGI script file dir
(POST).
#
# Modules to load
#
ns_section "ns/server/${servername}/modules"
ns_param nssock ${bindir}/nssock${ext}
ns_param nslog ${bindir}/nslog${ext}
#ns_param nscgi ${bindir}/nscgi${ext} ;# Map the paths before
using.
#ns_param nsperm ${bindir}/nsperm${ext} ;# Edit passwd before
using.
#
# MARK'S STUFF
# aolserver.com/docs/admin/driv-ch5.htm#38973
#
ns_section "ns/db/drivers"
ns_param freetds nsfreetds.so
ns_section "ns/db/pools"
ns_param mypool "this pool will point to SQL on markhpc"
ns_section "ns/db/pool/mypool"
ns_param Driver freetds
ns_param Datasource "markhpc"
# i have a feeling this should refer to a server in "interfaces" file
# or it might be TCP/IP hostname port
ns_param Connections 1
# this is max # concurrent connections to SQL.
ns_param LogSQLErrors on
ns_param User sa
ns_param Password ""
ns_param Verbose on
ns_section "ns/server/server1/db"
ns_param Pools *
#
# nsssl: Only loads if sslcertfile and sslkeyfile exist (see above).
#
if { [file exists $sslcertfile] && [file exists $sslkeyfile] } {
ns_param nsssl ${bindir}/${sslmodule}
} else {
ns_log warning "config.tcl: nsssl not loaded -- key/cert files do not
exist."
}
#
# nscp: Only loads if nscp_user is set (see above).
#
if { $nscp_user != "" } {
if ![string match "127.0.0.1" $nscp_addr] {
# Anything but 127.0.0.1 is not recommended.
ns_log warning "config.tcl: nscp listening on ${nscp_addr}:${nscp_port}"
}
ns_param nscp ${bindir}/nscp${ext}
} else {
ns_log warning "config.tcl: nscp not loaded -- user/password is not
set."
}
ns_log notice "config.tcl: finished reading config file."
==========================================
<% # $Id: nsfreetds.adp,v 1.3 2001/05/14 06:49:40 dossy Exp $ %>
<%
set form [ns_getform]
set action {}
if {$form != {}} {
set action [ns_set get $form action]
}
if [string match $action {Execute Query}] {
ns_puts {
<font face="Arial, Helvetica, sans-serif" size="2">
<form method="POST" action="nsfreetds.adp">
<p><input type="submit" value="New Query">
</form>
<p>(If this is the only thing you see on the page, most likely there
was an error thrown in the server.log.)
}
set datasource [ns_set get $form datasource]
set stored_proc [string trim [ns_set get $form stored_proc]]
set sql [string trim [ns_set get $form sql]]
# patch removed $datasource from the gethandle command
if [catch {set db [ns_db gethandle]} err] {
ns_puts "<p>Error connecting to datasource."
ns_adp_return
}
ns_db verbose $db 1
ns_puts [subst {
<p>Time: [ns_fmttime [ns_time]]
<p>Datasource: [switch -exact $datasource {
markhpc { return "markhpc SQL Server" }
heisler { return "Hal Heisler's SQL Server" }
jerry { return "Jerry Asher's SQL Server 7 SP2 (port 1472)" }
jerry2 { return "Jerry Asher's SQL Server 7 (port 1470)" }
michael { return "Michael Roberts's SQL Server" }
sybase { return "Dossy's Sybase 11.9.2 Server" }
}]
<p>SQL:
<font size="3">
<blockquote><xmp>$sql</xmp></blockquote>
</font>
<p>Results:
<p>
<font size="3">
<blockquote><xmp>}]
if [string match $stored_proc true] {
set err [catch {
ns_db sp_start $db $sql
ns_db sp_exec $db
} results]
} else {
set err [catch {ns_db exec $db $sql} results]
}
if {$err} {
ns_puts "error: $results"
} else {
if [string match $results NS_DML] {
ns_puts "DDL or DML statement, no results."
} else {
set row [ns_db bindrow $db]
set row_num 1
while {[ns_db getrow $db $row]} {
set size [ns_set size $row]
ns_puts "Row $row_num ..."
for {set i 0} {$i < $size} {incr i} {
ns_puts "Column [expr $i + 1]: [ns_set key $row $i]
= [ns_set value $row $i]"
}
incr row_num
}
}
}
ns_puts [subst {</xmp></blockquote>
</font>
<p>Rows affected: [ns_freetds rows_affected $db]
</font>
}]
} else {
ns_puts {
<font face="Arial, Helvetica, sans-serif" size="2">
<form method="post" action="nsfreetds.adp">
<input type="hidden" name="action" value="Execute Query">
<p>Datasource:
<select name="datasource">
<option value="markhpc">markhpc SQL Server</option>
<option value="heisler">Hal Heisler's SQL Server</option>
<option value="jerry">Jerry Asher's SQL Server 7 SP2 (port
1472)</option>
<option value="jerry2">Jerry Asher's SQL Server 7 (port
1470)</option>
<option value="michael">Michael Roberts's SQL Server</option>
<option value="sybase">Dossy's Sybase 11.9.2 Server</option>
</select>
<p>SQL: (Stored Procedure? <input type="checkbox" name="stored_proc"
value="true">)<br>
<textarea name="sql" cols="60" rows="20" wrap="hard">
SELECT db_name() dbname,
user_name() username,
@@servername server,
@@version version,
getdate() now,
convert(varchar(26), getdate(), 9) nowhey,
convert(varchar(8), getdate(), 1) nowtoo,
convert(datetime, '12/31/1999') nowthen,
convert(money, '$10.52') cha_ching,
convert(numeric, '8675309') jenny_jenny,
convert(real, '123.456') get_real,
convert(text, 'this is some text') some_text,
convert(datetime, null) datetime_null,
convert(integer, null) integer_null,
convert(real, null) real_null,
convert(numeric, null) numeric_null,
convert(money, null) money_null,
convert(varchar(10), null) varchar_null,
convert(text, null) text_null
</textarea>
<p><input type="submit" value="Execute Query">
</form>
</font>
}
}
%>
--
Mark Hubbard: [EMAIL PROTECTED]
Microsoft Certified Professional
"Knowledge is Power."